Coding Help Please

Questions about MultiCharts and user contributed studies.
masterchanger
Posts: 36
Joined: 03 Sep 2013
Location: Chicago, IL
Has thanked: 14 times
Been thanked: 12 times

Coding Help Please

Postby masterchanger » 13 Mar 2014

I'm trying to write a control code in a function.
I'm try to detect when a stoploss has been hit and to prevent reentry in the same direction as the stopout. Once that reentry occurs I'd like trading to resume as normal, unless that position is stopped out. I write signal orders to a printlog. The code I've come up with prevents same entry from stop out but doesn't return the signal to regular trading. it gets stuck, doesn't take profit or reverse and seems to just wait for another stopout and reverse. I've tried adding a "break;" in the code and get "illegal break" on compile.

Code: Select all

{If short hit prevent same entry trade only allow long and vice versa}
If PositionProfit(1)<-500 and MP=0 then begin // seems like a crude way to detect a stopout but I couldn't think of another way in a function
Switch MP1 begin
Case >0:
EntryOK = true;
BuyLimitOK = false;
SellLimitOK = true;
Case <0:
EntryOK = true;
BuyLimitOK = true;
SellLimitOK = false;
//Case =0:
//EntryOK = true;
//BuyLimitOK = true;
//SellLimitOK = true;
end;
end;

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Coding Help Please

Postby MAtricks » 13 Mar 2014

This might help.. (not tested) I don't think that a switch statement is needed with 2 uses.

Code: Select all

Variables:
Stoploss( false ) ;

if mp=0 and mp[1]<>0 and PositionProfit(1)<0 then Stoploss = true ;

if Stoploss = false then begin //code
end ;
if Stoploss = true then begin //code
end ;


Return to “MultiCharts”