oppz
January 3, 2022, 8:00pm
#1
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.
fxshrat
January 3, 2022, 11:36pm
#2
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 !!!
Gaps in general and gaps on open (between close of previous bar and open of next bar) are your answer. Stops don't occur in void. They occur in actual tradeable price levels. If that happens that gap is wider then you will get more profit.
oppz
January 4, 2022, 6:12pm
#3
It was the volatile
argument that was the reason for the "wrong" values, when 0
on that one everything worked perfectly. Thanks.
system
Closed
April 14, 2022, 6:13pm
#4
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.