I think you have to Normalize expressions "Bid-Trailingstop*Point" and "Ask + Trailingstop*Point" because Trailingstop is double.
Didnt help :-/
the problem has to be somewhere else...but thank you anyway ;-)
Didnt help :-/
the problem has to be somewhere else...but thank you anyway ;-)
Hard to be certain, because you say you haven't posted the whole of the code. However, by the looks of it, Trailingstop isn't a static or global variable. It's declared in the "bullish" section. Therefore, its value will get set at the time an order is placed, but won't persist after that. On subsequent calls to start(), when an order is modified, the Trailingstop variable should contain zero. Therefore, the call to OrderModify() will be trying to set the stop to either Ask + 0 * Point or Bid + 0 * Point.
Hard to be certain, because you say you haven't posted the whole of the code. However, by the looks of it, Trailingstop isn't a static or global variable. It's declared in the "bullish" section. Therefore, its value will get set at the time an order is placed, but won't persist after that. On subsequent calls to start(), when an order is modified, the Trailingstop variable should contain zero. Therefore, the call to OrderModify() will be trying to set the stop to either Ask + 0 * Point or Bid + 0 * Point.
EXACTLY.... That is what I have thought, but I dont see any way, how to solve it. Unfortunately, I havent been programming for a long time. So do you see any way, how to maintain the value of Trailingstop for the next repetition of the program? I guess that would push a little bit forward with this EA ..... And thank you all for your responses
2009.05.18 22:31:51 1999.05.17 08:54 Rady EURUSD,Daily: Bid - 1.0674 TrailingStop - 0 OrderStopLoss - 1.1087 Bid-Trailingstop*Point - 1.067400
Trailing stop equals 0. That confirms JJC'S post. So how do I maintain the value of the Trailingstop for another program run? I was thinking about giving that value into order ticket or magic number, but I am sure that there are better ways, how to do it.
And this is the rest of the code.
#property copyright "Boocha" int cnt; int Trailingstop; int start() // Special function 'start' { int total = OrdersTotal(); int cnt; if ( OrdersTotal() ==0) // IF THERE IS NO ORDER { int timeold; if (timeold!=Time[0]) { timeold=Time[0]; double O=Open[1]; double C=Close[1]; double L=Low[1]; double H=High[1]; int ticket; double Risk = 0.02; double StopLossPoints, lots; double ma1 = iMA(NULL,PERIOD_W1,20,0,MODE_SMA,PRICE_CLOSE,6); double ma2 = iMA(NULL,PERIOD_W1,20,0,MODE_SMA,PRICE_CLOSE,1); double MarginAmount = AccountEquity()*Risk; //----BULLISH
Hi
Try putting a slippage other than zero and check that 100 points is what you think and not 10 points on a 5 decimal place platform. Print out the values just after the trade to see they are correct maybe indicator is returning dodgy values sometimes.
2009.05.18 22:50:02 2005.02.01 00:00 Rady EURUSD,Daily: open #2 buy stop 0.20 EURUSD at 1.3071 sl: 1.2963 tp: 1.3382 ok
2009.05.18 22:50:02 2005.02.01 00:00 Rady EURUSD,Daily: TS-108
This part should be ok. Trailing stop is really 108 points.
Trailing stop equals 0. That confirms JJC'S post. So how do I maintain the value of the Trailingstop for another program run? I was thinking about giving that value into order ticket or magic number, but I am sure that there are better ways, how to do it.
Try declaring Trailingstop as static double rather than just double. That should survive everything other than reloads of the EA. To handle restarts, you'll need to put the value in a global variable (GlobalVariableSet), or in a text object on the chart, or store it in a file.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have created an EA, that works well for me, but I tried to change it a little bit, but can not manage to make it work. All I want it to do is to open an order with a trailing stop. The problem is, the trailing stop is different for each trade (it depends on the high of the current candle). It always gives ordermodify error 130, which means that the stop loss is too close. That is not possible, cause I trade daily and the stop loss is always at least 100 pips. I guess the problem could be that it somehow always calculates the trailing stop 0, cause the trailing stop is always calculated right after the trade is placed and the ordermodify function is started after that. But I tried to put the trailing stop 150 for instance and it still gives me that error ( but this time only sometimes). If anyone could help, I would be really pleased. Thx here is the code (it is not whole, it wouldnt fit here)