I'm having problem in increasing lot size after winning (reverse martingale) .
The EA worked on backtest environment, but in real trading it's only placing same-lot-size-trades despite winning or losing.
I tried selecting the last ticket profit through SELECT_BY_POS as well as SELECT_BY_TICKET. None of them gave me the result I wanted.
Any help would be appreciated ! Thank u !
It looks like, that lastOrder is always -1.. Or?
You should position the brackets a little better. ;-)
It looks like, that lastOrder is always -1.. Or?
You should position the brackets a little better. ;-)
sorry, the brackets were auto-alignment, i didn't notice.
For a better understanding: (Is it what you are thinking about?)
void OnTick() { if (IsBuyCond()) // Method not included here { if (OrderSelect(lastOrder, SELECT_BY_TICKET, MODE_HISTORY)) { if (OrderProfit() > 0 && OrderLots() < 0.04) { lot = 0.05; } else lot = 0.03; } lastOrder = OrderSend(Symbol(), OP_BUY, lot, Ask, 3*Point, 0, 0, "EA", 1234, 0, clrRed); } else if (IsSellCond()) // Method not included here { if (OrderSelect(lastOrder, SELECT_BY_TICKET, MODE_HISTORY)) { if (OrderProfit() > 0 && OrderLots() < 0.04) { lot = 0.05; } else lot = 0.03; } lastOrder = OrderSend(Symbol(), OP_SELL, lot, Bid, 3*Point, 0, 0, "EA", 1234, 0, clrGreen); } }
I can not test it, because I don't know, what your BUY CONDITION MET and SELL CONDITION MET are doing here.
I've replaced them with the funcions IsBuyCond() and IsSellCond().
You should check every "if" in the debug mode. Add breakpoints at the important lines and read out all variables.
For a better understanding: (Is it what you are thinking about?)
I can not test it, because I don't know, what your BUY CONDITION MET and SELL CONDITION MET are doing here.
I've replaced them with the funcions IsBuyCond() and IsSellCond().
You should check every "if" in the debug mode. Add breakpoints at the important lines and read out all variables.
yeah u got my idea, above code is exactly what i mean. I just discovered something new : the EA would increase the size if the last trade and new trade were on same symbol (such as EURUSD for these 2 trades). if there were other symbol trades between them then it won't work.
Maybe you've changed the symbol on the chart, where and while this EA is running. In this case the value of 'lastOrder' gets lost, because changing the symbol on the current chart reloads the EA on the chart.
Maybe you've changed the symbol on the chart, where and while this EA is running. In this case the value of 'lastOrder' gets lost, because changing the symbol on the current chart reloads the EA on the chart.
Hard to say, because nobody knows the rest of your code. ;-)
Try logging with "Print". (Example on IsSellCond())
(I did not test the following code. ;-)
void OnTick() { if (IsBuyCond()) // Method not included here { if (OrderSelect(lastOrder, SELECT_BY_TICKET, MODE_HISTORY)) { if (OrderProfit() > 0 && OrderLots() < 0.04) { lot = 0.05; } else lot = 0.03; } lastOrder = OrderSend(Symbol(), OP_BUY, lot, Ask, 3*Point, 0, 0, "EA", 1234, 0, clrRed); } else if (IsSellCond()) // Method not included here { Print("Found sell condition."); if (OrderSelect(lastOrder, SELECT_BY_TICKET, MODE_HISTORY)) { Print("Selecting last order with ticket " + IntegerToString(lastOrder) + " ok."); if (OrderProfit() > 0 && OrderLots() < 0.04) { lot = 0.05; } else lot = 0.03; } lastOrder = OrderSend(Symbol(), OP_SELL, lot, Bid, 3*Point, 0, 0, "EA", 1234, 0, clrGreen); if (lastOrder == -1) { Print("Failed to open new SELL order."); } else { Print("Opened new SELL order. Ticket: " + IntegerToString(lastOrder) + ", lots: " + DoubleToStr(lot, 2)); } } }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm having problem in increasing lot size after winning (reverse martingale) .
The EA worked on backtest environment, but in real trading it's only placing same-lot-size-trades despite winning or losing.
I tried selecting the last ticket profit through SELECT_BY_POS as well as SELECT_BY_TICKET. None of them gave me the result I wanted.
Any help would be appreciated ! Thank u !
Here's my code :
//+------------------------------------------------------------------+
//| HubbaHubbaVer1.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//
// INCLUDE FILE
//
#include <IndicatorValue.mqh>
#include <CandlePattern.mqh>
#include <StrategyTester.mqh>
extern double lot = 0.03f;
int lastOrder = -1;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if (//BUY CONDITION MET)
{
//also tried OrderSelect(OrderHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)
if (OrderSelect(lastOrder,SELECT_BY_TICKET)==TRUE)
{
if (OrderProfit() > 0 && (float)NormalizeDouble(OrderLots(),2) < 0.04f)
// or OrderLots() == 0.03 ; lot == 0.03 <== I tried these already
{
lot = 0.05f;
}
else lot = 0.03f;
}
lastOrder = OrderSend(Symbol(),OP_BUY,lot,Ask,3*Point,0,0,"EA",1234,0,clrRed);
}
else if(//SELL CONDITION MET)
{
if (OrderSelect(lastOrder,SELECT_BY_TICKET)==TRUE)
{
if (OrderProfit() > 0 && (float)NormalizeDouble(OrderLots(),2) < 0.04f)
{
lot = 0.05f;
}
else lot = 0.03f;
}
lastOrder = OrderSend(Symbol(),OP_SELL,lot,Bid,3*Point,0,0,"EA",1234,0,clrGreen);
}
}
}
}