Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

Ptt5566

Help on Coding in Multicharts , Please....

Recommended Posts

Hello,

 

I am a newer trying to develop trading strategy , but the result is no good.

 

My coding is as follows:-

 

 

inputs: High_Length( 20),Low_Length( 20 ),add1(150),add2(300),add3(450),add4(600),stopProfit(50);

variables: var0( 0 ),var1( 0 ) ;

variables: kb(0),eb(0),es(0),kbarb(0),ks(0),kbars(0) ;

 

var0 = AverageFC( high, High_Length ) ;

var1 = AverageFC( low, Low_Length) ;

 

//============Condition=======================================

if high[1]>var0 and high>var0 and high[2]>var0 and high[1]>high and high[1]>high[2] then

value1=highest(high,3);

 

if low[1]<var1 and low<var1 and low[2]<var1 and low[1]<low and low[1]<low[2] then

value2=lowest(low,3);

 

//=============Entry/Exit=======================================

if close crosses over value1 and high>var0 and eb=0 then begin

buy next bar at market;

kb=close;

eb=1;

es=0;

kbarb=BarNumber;

end;

 

if close crosses under value2 and low<var1 and es=0 then begin

sellshort next bar at market;

ks=close;

es=1;

eb=0;

kbars=BarNumber;

end;

 

 

//=============Add Shares=====================================

//====buy

if marketposition*currentcontracts=1 then

buy("Add_Buy1") 1 shares next bar at kb+add1 stop;

 

if marketposition*currentcontracts=2 then

buy("Add_Buy2") 1 shares next bar at kb+add2 stop;

 

 

if marketposition*currentcontracts=3 then

buy("Add_Buy3") 1 shares next bar at kb+add3 stop;

 

 

if marketposition*currentcontracts=4 then

buy("Add_Buy4") 1 shares next bar at kb+add4 stop;

 

 

 

 

//====sell

 

if marketposition*currentcontracts=-1 then

sellshort("Add_Sell1") 1 shares next bar at ks-add1 stop;

 

if marketposition*currentcontracts=-2 then

sellshort("Add_Sell2") 1 shares next bar at ks-add2 stop;

 

if marketposition*currentcontracts=-3 then

sellshort("Add_Sell3") 1 shares next bar at ks-add3 stop;

 

if marketposition*currentcontracts=-4 then

sellshort("Add_Sell4") 1 shares next bar at ks-add4 stop;

 

 

 

 

//==============Exit Add========================

 

 

 

value11=BarNumber-kbarb;

value12=BarNumber-kbars;

 

value3=highest(high,barssinceentry )-stopProfit;

value4=lowest(low,barssinceentry)+stopProfit;

//print(kbarb,kbars);

 

if marketposition*currentcontracts>=2 then sell from entry("add_buy1") next bar at value3 Stop;

if marketposition*currentcontracts>=2 then sell from entry("add_buy2") next bar at value3 Stop;

if marketposition*currentcontracts>=2 then sell from entry("add_buy3") next bar at value3 Stop;

if marketposition*currentcontracts>=2 then sell from entry("add_buy4") next bar at value3 Stop;

 

 

if marketposition*currentcontracts<=-2 then buytocover from entry("Add_Sell1")next bar at value4 stop;

if marketposition*currentcontracts<=-2 then buytocover from entry("Add_Sell2")next bar at value4 stop;

if marketposition*currentcontracts<=-2 then buytocover from entry("Add_Sell3")next bar at value4 stop;

if marketposition*currentcontracts<=-2 then buytocover from entry("Add_Sell4")next bar at value4 stop;

 

 

When I exit add , there should be only one position(First entry/exit) in the market ,others all clear.

 

But the Add Shares Instruction is actioning again and again.

 

This bug how to fix ? please help me.

 

Thanks everyone in advance.

ptt5566.thumb.JPG.8e3cdb0ce3d3aaa6847f58c0220e7e7b.JPG

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.