You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Oh man you really are a star. I love to trade, but it would be impossible without your help. Thanks again
Hi,
Could someone please help me with my LotsizeCalc() function.
I would like to multiply my lotsize with the 'MartingaleAmount' if my last trade was a loser. If my last trade was a winner I would like to use the 'normal' lotsize. Unfortunately, when I backtest the EA I get error 4051 from the journal.
It has something to do with the lotsize, because the EA works when I try to run the EA without the "LotsizeCalc()" function.
Does anyone know why my lotsize function won't work?
Thanks in advance,
Thierry
extern int MaximumTrades = 10; extern double StopLoss=25; extern double TakeProfit=50; extern double MartingaleAmount = 1.5; input double LotSize=0.1; int magic; double pips; int tradeNumber; string ScreenComment; double martinlot; double martinsize;
[/PHP]
Thierry
You can use this function to find out if the last closed order was closed with profit or loss :
[PHP]double lastOrderProfit(int magicNumber=0)
{
datetime lastTime = 0;
double lastProfit = 0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;
if (magicNumber!=0)
if (OrderMagicNumber() != magicNumber) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderCloseTime() <= lastTime) continue;
lastTime = OrderCloseTime();
lastProfit = OrderProfit()+OrderSwap()+OrderCommission();
}
return(lastProfit);
}
Just check if the result of lastOrderProfit() function, and if it is < 0, then apply your martingale rule
Hi Mladen! Me again...
How would it be possible to use the lines from this indicator in an EA using iCustom since there doesn't seem to be any buffers set for these lines?
Thanks
Hi Mladen! Me again...
How would it be possible to use the lines from this indicator in an EA using iCustom since there doesn't seem to be any buffers set for these lines?
ThanksThose are objects
You can access objects by name (you must know the exact name of the object, but the indicator must be active on the chart and those objects must be drawn on chart).
Those are objects You can access objects by name (you must know the exact name of the object, but the indicator must be active on the chart and those objects must be drawn on chart).
Great. So how would I call the indicator from the EA? With something other than iCustom or have I got it all wrong... Thanks mladen
Great. So how would I call the indicator from the EA? With something other than iCustom or have I got it all wrong... Thanks mladen
That indicator simply draws levels at 0,20,50,80 pips of each 100 pips segment. The simplest way is to check if those levels are crossed from your EA.
If you try using object names (and their prices, you will not be able to know the exact names of the lines since they depend on highest high and lowest low - they are a subject of change. Use the mode described above
That indicator simply draws levels at 0,20,50,80 pips of each 100 pips segment. The simplest way is to check if those levels are crossed from your EA. If you try using object names (and their prices, you will not be able to know the exact names of the lines since they depend on highest high and lowest low - they are a subject of change. Use the mode described above
Would you have an example on how to do that... I'm sorry for asking so much, I just am starting out with coding and haven't got the hang of how to check if those levels are crossed in the condition to buy or sell.
Would you have an example on how to do that... I'm sorry for asking so much, I just am starting out with coding and haven't got the hang of how to check if those levels are crossed in the condition to buy or sell.
Jason2005
You have a code how it is done in the indicator you attached
Jason2005 You have a code how it is done in the indicator you attached
Would it be this then?
Thierry
You can use this function to find out if the last closed order was closed with profit or loss :
{
datetime lastTime = 0;
double lastProfit = 0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;
if (magicNumber!=0)
if (OrderMagicNumber() != magicNumber) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderCloseTime() <= lastTime) continue;
lastTime = OrderCloseTime();
lastProfit = OrderProfit()+OrderSwap()+OrderCommission();
}
return(lastProfit);
}
Hi Mladen,
Thanks for your response.
The lastorderprofit function isn't needed because my lastTradeTicket() function does the same job.
Could you please give a look at my EA?
I'm not asking you to edit the code, but I would be very thankful if you could tell me what I coded wrong.
Thanks in advance,
Thierry
53_martingale.mq4