Diffrent ApplyStop for Long & short - Problem with code

Hi

I am trying to investigate if different StopTypeProfit / Loss should be used in a system, and that part of the code looks like;

tp_m_L = 1;
sl_m_L = 1;

tp_m_s = 2;
sl_m_s = 2;

tp_m = IIf(buy , tp_m_L , (IIf(short ,tp_m_s,0)));
SL_m = IIf(buy , sl_m_L , (IIf(short ,sl_m_s,0)));

ApplyStop( stopTypeProfit, stopModePercent, tp_m, 1, 1, 1, 0 );     
ApplyStop( stopTypeLoss, stopModePercent, SL_m , 1, 1, 1, 0 );   

This will unfortunately only give wrong values.

If I put tp_m = 1 , it will give the correct value... What can be wrong? The strange thing is that when I run an Exploration to debug the code, the tp_m value seems to be correct.

No one can read your mind. No one knows what you consider being "wrong".
AmiBroker does what you tell it via your code!

Besides code is incomplete!

Remove volatile argument of ApplyStop being TRUE!
Besides there is only Buy or Short so you can remove nested iif.

m = MA( Close, 20 ); 
Buy = Cross( Close, m ); 
Sell = Cross( m, Close ); 
Short = Sell;
Cover = Buy;

tp_m_L = 1;
sl_m_L = 1;

tp_m_s = 2;
sl_m_s = 2;

tp_m = IIf(buy , tp_m_L , tp_m_s);
SL_m = IIf(buy , sl_m_L , sl_m_s);

ApplyStop( stopTypeProfit, stopModePercent, tp_m, 1, 0, 1, 0 );     
ApplyStop( stopTypeLoss, stopModePercent, SL_m , 1, 0, 1, 0 ); 

Besides price array may have gaps!!!

It was the volatile argument that was the reason for the "wrong" values, when 0 on that one everything worked perfectly. Thanks.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.