You could check the Experts and Journal tabs to see if any errors are generated when it tries to open positions.
Hello there,
Thankyou, this is very interesting.
I have been trading Forex for about an year now, and I can say that most of the time the Market is random due to News events, natural disasters, wars etc...
But the market can only go in 3 directions:
1)Ranging
2)Up
3)Down
When it goes Up or Down, it doesn't go in a straight line, but only in Fibonacci retracements. This is the only pattern that I see in Forex.
So the fact that you use a random entry period, is a very good idea to work with the Fib tracements.
Anyhow, with the myRandom ea suing default settings., if it opens 5 trades a month, there is only 1/6 chances 16% of chance you can loose, and 84% of chance of making a profit- ranging from small profits to large profits.
Its all about probability.
There's so many Eas out there that try to trade according to some pattern and most of them don't even reach 90% success rate- and there is no gurantee that is will continue to work in future market conditions. This is worry- better to change something that is random, which will work in all market conditions.
Like throwing a dice, how many times will 6 come up?
or 1 come up?
Thanks alot
Tony
if ((NewSL > OrderStopLoss()) || (OrderStopLoss() == 0)) // here goes OrderModify() with new SL
if ((NewSL < OrderStopLoss()) || (OrderStopLoss() == 0)) // here goes OrderModify() with new SL
extern double Lots = 0.1; extern double Slippage = 3; extern int RandomEntryPeriod = 80; //In bars. How many bars to wait before entering a new position. extern int StopLoss = 90; extern int TakeProfit = 600; extern int MaxPositions = 4; extern bool ECN_Mode = false; // In ECN mode, SL and TP aren't applied on OrderSend() but are added later with OrderModify() extern color clOpenBuy = Blue; extern color clOpenSell = Red; int Magic; int LastBars = 0; int OrderTaken = 0; double Poin; int Deviation; int init() { //Checking for unconvetional Point digits number if ((Point == 0.00001) || (Point == 0.001)) { Poin = Point * 10; Deviation = Slippage * 10; } else { Poin = Point; //Normal Deviation = Slippage; } Magic = Period()+1339005; return(0); } //+------------------------------------------------------------------+ //| Random entry expert advisor | //+------------------------------------------------------------------+ int start() { if (ECN_Mode) DoSLTP(); if (LastBars == Bars) return(0); else LastBars = Bars; if (AccountFreeMargin() < (Lots*2*1000)) return(0); if (Lots < 0.1) return(0); MathSrand(TimeLocal()); int count = 0; int total = OrdersTotal(); for (int pos = 0; pos < total; pos++) { if (OrderSelect(pos, SELECT_BY_POS) == false) continue; if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) count++; } if (count >= MaxPositions) return(0); if (Bars >= OrderTaken + RandomEntryPeriod) { if ((MathRand()%2) == 1) { fSell(); } else { fBuy(); } OrderTaken = Bars; } } //+------------------------------------------------------------------+ //| Buy | //+------------------------------------------------------------------+ void fBuy() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Ask - StopLoss * Poin; if (TakeProfit > 0) TP = Ask + TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_BUY, Lots, Ask, Deviation, SL, TP, "myRandom", Magic, 0, clOpenBuy); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Sell | //+------------------------------------------------------------------+ void fSell() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Bid + StopLoss * Poin; if (TakeProfit > 0) TP = Bid - TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_SELL, Lots, Bid, Deviation, SL, TP, "myRandom", Magic, 0, clOpenSell); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Applies SL and TP to open positions if ECN mode is on. | //+------------------------------------------------------------------+ void DoSLTP() { double SL = 0, TP = 0; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) { RefreshRates(); if (OrderType() == OP_BUY) { if (StopLoss > 0) SL = NormalizeDouble(Ask - StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Ask + TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL > OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, 0, 0); } } else if (OrderType() == OP_SELL) { if (StopLoss > 0) SL = NormalizeDouble(Bid + StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Bid - TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL < OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, 0, 0); } } } } }
extern double Lots = 0.1; extern double Slippage = 3; extern int RandomEntryPeriod = 80; //In bars. How many bars to wait before entering a new position. extern int StopLoss = 90; extern int TakeProfit = 600; extern int MaxPositions = 4; extern bool ECN_Mode = false; // In ECN mode, SL and TP aren't applied on OrderSend() but are added later with OrderModify() extern color clOpenBuy = Blue; extern color clOpenSell = Red; int Magic; int LastBars = 0; int OrderTaken = 0; double Poin; int Deviation; int init() { //Checking for unconvetional Point digits number if ((Point == 0.00001) || (Point == 0.001)) { Poin = Point * 10; Deviation = Slippage * 10; } else { Poin = Point; //Normal Deviation = Slippage; } Magic = Period()+1339005; return(0); } //+------------------------------------------------------------------+ //| Random entry expert advisor | //+------------------------------------------------------------------+ int start() { if (ECN_Mode) DoSLTP(); if (LastBars == Bars) return(0); else LastBars = Bars; if (AccountFreeMargin() < (Lots*2*1000)) return(0); if (Lots < 0.1) return(0); MathSrand(TimeLocal()); int count = 0; int total = OrdersTotal(); for (int pos = 0; pos < total; pos++) { if (OrderSelect(pos, SELECT_BY_POS) == false) continue; if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) count++; } if (count >= MaxPositions) return(0); if (Bars >= OrderTaken + RandomEntryPeriod) { if ((MathRand()%2) == 1) { fSell(); } else { fBuy(); } OrderTaken = Bars; } } //+------------------------------------------------------------------+ //| Buy | //+------------------------------------------------------------------+ void fBuy() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Ask - StopLoss * Poin; if (TakeProfit > 0) TP = Ask + TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_BUY, Lots, Ask, Deviation, SL, TP, "myRandom", Magic, 0, clOpenBuy); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Sell | //+------------------------------------------------------------------+ void fSell() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Bid + StopLoss * Poin; if (TakeProfit > 0) TP = Bid - TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_SELL, Lots, Bid, Deviation, SL, TP, "myRandom", Magic, 0, clOpenSell); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Applies SL and TP to open positions if ECN mode is on. | //+------------------------------------------------------------------+ void DoSLTP() { double SL = 0, TP = 0; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) { RefreshRates(); if (OrderType() == OP_BUY) { if (StopLoss > 0) SL = NormalizeDouble(Ask - StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Ask + TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL > OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } else if (OrderType() == OP_SELL) { if (StopLoss > 0) SL = NormalizeDouble(Bid + StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Bid - TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL < OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } } } }
extern double Lots = 0.1; extern double Slippage = 3; extern int RandomEntryPeriod = 80; //In bars. How many bars to wait before entering a new position. extern int StopLoss = 90; extern int TakeProfit = 600; extern int MaxPositions = 4; extern int TrailingStop = 20; extern bool ECN_Mode = false; // In ECN mode, SL and TP aren't applied on OrderSend() but are added later with OrderModify() extern color clOpenBuy = Blue; extern color clOpenSell = Red; int Magic; int LastBars = 0; int OrderTaken = 0; double Poin; int Deviation; int init() { //Checking for unconvetional Point digits number if ((Point == 0.00001) || (Point == 0.001)) { Poin = Point * 10; Deviation = Slippage * 10; } else { Poin = Point; //Normal Deviation = Slippage; } Magic = Period()+1339005; return(0); } //+------------------------------------------------------------------+ //| Random entry expert advisor | //+------------------------------------------------------------------+ int start() { if (ECN_Mode) { DoTrailing(); DoSLTP(); } if (LastBars == Bars) return(0); else LastBars = Bars; if (AccountFreeMargin() < (Lots*2*1000)) return(0); if (Lots < 0.1) return(0); MathSrand(TimeLocal()); int count = 0; int total = OrdersTotal(); for (int pos = 0; pos < total; pos++) { if (OrderSelect(pos, SELECT_BY_POS) == false) continue; if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) count++; } if (count >= MaxPositions) return(0); if (Bars >= OrderTaken + RandomEntryPeriod) { if ((MathRand()%2) == 1) { fSell(); } else { fBuy(); } OrderTaken = Bars; } } //+------------------------------------------------------------------+ //| Buy | //+------------------------------------------------------------------+ void fBuy() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Ask - StopLoss * Poin; if (TakeProfit > 0) TP = Ask + TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_BUY, Lots, Ask, Deviation, SL, TP, "myRandom", Magic, 0, clOpenBuy); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Sell | //+------------------------------------------------------------------+ void fSell() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Bid + StopLoss * Poin; if (TakeProfit > 0) TP = Bid - TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_SELL, Lots, Bid, Deviation, SL, TP, "myRandom", Magic, 0, clOpenSell); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Applies SL and TP to open positions if ECN mode is on. | //+------------------------------------------------------------------+ void DoSLTP() { double SL = 0, TP = 0; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) { RefreshRates(); if (OrderType() == OP_BUY) { if (StopLoss > 0) SL = NormalizeDouble(Ask - StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Ask + TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL > OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } else if (OrderType() == OP_SELL) { if (StopLoss > 0) SL = NormalizeDouble(Bid + StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Bid - TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL < OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } } } } void DoTrailing() { int total = OrdersTotal(); for (int pos = 0; pos < total; pos++) { if (OrderSelect(pos, SELECT_BY_POS) == false) continue; if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) { if (OrderType() == OP_BUY) { RefreshRates(); if (Bid - OrderOpenPrice() >= TrailingStop * Poin) //If profit is greater or equal to the desired Trailing Stop value { if (OrderStopLoss() < (Bid - TrailingStop * Poin)) //If the current stop-loss is below the desired trailing stop level OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * Poin, OrderTakeProfit(), 0); } } else if (OrderType() == OP_SELL) { RefreshRates(); if (OrderOpenPrice() - Ask >= TrailingStop * Poin) //If profit is greater or equal to the desired Trailing Stop value { if ((OrderStopLoss() > (Ask + TrailingStop * Poin)) || (OrderStopLoss() == 0)) //If the current stop-loss is below the desired trailing stop level OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop * Poin, OrderTakeProfit(), 0); } } } } }
void DoSLTP() { double SL = 0, TP = 0; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) { if (OrderType() == OP_BUY) { if (StopLoss > 0) SL = NormalizeDouble(OrderOpenPrice() - StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(OrderOpenPrice() + TakeProfit * Poin, Digits); if (((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) && (OrderStopLoss() == 0) && (OrderTakeProfit() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } else if (OrderType() == OP_SELL) { if (StopLoss > 0) SL = NormalizeDouble(OrderOpenPrice() + StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(OrderOpenPrice() - TakeProfit * Poin, Digits); if (((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) && (OrderStopLoss() == 0) && (OrderTakeProfit() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } } } }
if (Bid - OrderOpenPrice() >= TrailingStop * Poin) //If profit is greater or equal to the desired Trailing Stop value
if (Bid >= OrderOpenPrice())
if (OrderOpenPrice() - Ask >= TrailingStop * Poin) //If profit is greater or equal to the desired Trailing Stop value
if (OrderOpenPrice() <= Ask)