#property show_inputs
#include <WinUser32.mqh>
#include <stdlib.mqh>
#define NL "\n"
#define highline "Next high round number"
#define highlinetradetrigger "Next buy trade trigger"
#define lowline "Next low round number"
#define lowlinetradetrigger "Next sell trade trigger"
/*
void DisplayUserFeedback()
start()
----Trading functions----
void LookForTradingOpportunity()
bool SendSingleTrade(int type, string comment, double lotsize, double price, double stop, double TP, int magic)
bool DoesTradeExist()
----Matt's Order Reliable library code
bool O_R_CheckForHistory(int ticket) Cheers Matt, You are a star.
void O_R_Sleep(double mean_time, double max_time)
*/
extern string bs="----Basic stuff----";
extern double Lot=0.01;
extern int MagicNumber=615046;
extern string TradeComment="Round numbers";
extern bool CriminalIsECN=false;
extern int TradeTriggerPips=15;
extern bool ReverseTradeDirection=false;
extern bool TakeFirstTrade=true;
extern string tpsl="----Stop loss----";
extern int StopLoss=100;
extern string TSL="----Trailing stop loss----";
extern int TrailingStopPips=15;
extern int BreakEvenProfitPips=1;
extern string trs="----Odds and ends----";
extern int DisplayGapSize=30;
extern bool DeleteLinesOnExit=true;
extern double bprice=1.3480;
extern double sprice=1.3460;
double sl = 20;
double TP = 20;
//Matt's O-R stuff
int O_R_Setting_max_retries = 10;
double O_R_Setting_sleep_time = 4.0; /* seconds */
double O_R_Setting_sleep_max = 15.0; /* seconds */
//Round numbers
double RoundNumberHigh, RoundNumberHighTrigger;
double RoundNumberLow, RoundNumberLowTrigger;
//Misc stuff
string ScreenMessage, Gap;
bool RobotDisabled;
string DisabledMessage;
int Spread;
void DisplayUserFeedback()
{
ScreenMessage = "";
ScreenMessage = StringConcatenate(ScreenMessage, Gap, NL);
ScreenMessage = StringConcatenate(ScreenMessage, Gap, "Lot size = ", Lot, NL);
ScreenMessage = StringConcatenate(ScreenMessage, Gap, "Stop loss = ", StopLoss, NL);
ScreenMessage = StringConcatenate(ScreenMessage,Gap, "Magic number = ", MagicNumber, NL);
double spread = MarketInfo(Symbol(), MODE_SPREAD);
ScreenMessage = StringConcatenate(ScreenMessage, Gap, "Spread = ", spread, NL);
ScreenMessage= StringConcatenate(ScreenMessage, NL);
Comment(ScreenMessage);
}//void DisplayUserFeedback()
//+------------------------------------------------------------------+
//| expert Initialization function |
//+------------------------------------------------------------------+
int init()
{
int multiplier;
if(Digits == 2 || Digits == 4) multiplier = 1;
if(Digits == 3 || Digits == 5) multiplier = 10;
if(Digits == 6) multiplier = 100;
if(Digits == 7) multiplier = 1000;
TradeTriggerPips*= multiplier;
StopLoss*= multiplier;
BreakEvenProfitPips*= multiplier;
Gap="";
if (DisplayGapSize >0)
{
for (int cc=0; cc< DisplayGapSize; cc++)
{
Gap = StringConcatenate(Gap, " ");
}
}
Comment(".........Waiting for a tick");
start();
}
//+------------------------------------------------------------------+
//| expert Deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
Comment("");
}
bool DoesTradeExist()
{
//Searches for open trades
if (OrdersTotal() == 0) return(false); //nothing to do
bool found = false;
for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
{
if (!OrderSelect(cc, SELECT_BY_POS) ) continue;
if (OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() )
{
found = true;
if (OrderProfit() > 0) TrailingStopLoss();
}
}
return(found);
}//End bool DoesTradeExist()
bool SendSingleTrade(int type, string comment, double lotsize, double price, double sl, double TP, int magic)
{
int slippage = 10;
if (Digits == 3 || Digits == 5) slippage = 100;
color col = Red;
if (type == OP_BUY || type == OP_BUYSTOP) col = Green;
int expiry = 0;
//if (SendPendingTrades) expiry = TimeCurrent() + (PendingExpiryMinutes * 60);
if (!CriminalIsECN) int ticket = OrderSend(Symbol(),type, lotsize, price, slippage, sl, TP, comment, magic, expiry, col);
//Is a 2 stage criminal
if (CriminalIsECN)
{
ticket = OrderSend(Symbol(),type, lotsize, price, slippage, 0, 0, comment, magic, expiry, col);
if (sl != 0)
{
if (ticket > 0)
bool result = OrderModify(ticket, OrderOpenPrice(), sl, TP, 0, CLR_NONE);
if (!result)
{
int err=GetLastError();
Print(Symbol(), " ", type," SL order modify failed with error(",err,"): ",ErrorDescription(err));
}//if (!result)
}//if (Sl != 0)
}//if (CriminalIsECN)
//Error trapping for both
if (ticket < 0)
{
string stype;
if (type == OP_BUY) stype = "OP_BUY";
if (type == OP_BUYSTOP) stype = "OP_BUYSTOP";
if (type == OP_SELL) stype = "OP_SELL";
if (type == OP_SELLSTOP) stype = "OP_SELLSTOP";
err=GetLastError();
Alert(Symbol(), " ", stype," Manual EA order send failed with error(",err,"): ",ErrorDescription(err));
Print(Symbol(), " ", stype," Manual EA order send failed with error(",err,"): ",ErrorDescription(err));
return(false);
}//if (ticket < 0)
//Make sure the trade has appeared in the platform's history to avoid duplicate trades
O_R_CheckForHistory(ticket);
//Got this far, so trade send succeeded
return(true);
}//End bool SendSingleTrade(int type, string comment, double lotsize, double price, double stop, double TP)
//START TRADE LOGIC//
void LookForTradingOpportunity()
{
if (IsTradeContextBusy() ) return;
double sl, TP;
RefreshRates();
bool result;
double MinStop = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point;
if (!ReverseTradeDirection)
{
//Long
if(Bid >= bprice)
{
if (TakeFirstTrade)
{
//First trade with tp
result = false;
while (result == false)
{
if (StopLoss > 0) sl = NormalizeDouble(Ask - (StopLoss * Point), Digits);
result = SendSingleTrade(OP_BUY, TradeComment, Lot, Ask, sl, TP, MagicNumber);
}//while (result = false)
}//if (TakeFirstTrade)
}//
//Short
// if (Bid <= lo && Open[0] > lo && lo > 0)
if(Bid <= sprice)
{
if (TakeFirstTrade)
{
//First trade with tp
result = false;
while (!result)
{
if (StopLoss > 0) sl = NormalizeDouble(Bid + (StopLoss * Point), Digits);
result = SendSingleTrade(OP_SELL, TradeComment, Lot, Bid, sl, TP, MagicNumber);
}//While (!result)
}//if (TakeFirstTrade)
}//if (Bid <= lo && Open[1] > lo && lo > 0)
}//if (!ReverseTradeDirection)
}//void LookForTradingOpportunity()
//END TRADE LOGIC //
I am getting error 130 Invalid stops , where could i have gone wrong ??
when i set extern int StopLoss=0; all is fine in terms of orders getting fired except that no tp or sl values are put in along with the order .
#include <WinUser32.mqh>
#include <stdlib.mqh>
#define NL "\n"
#define highline "Next high round number"
#define highlinetradetrigger "Next buy trade trigger"
#define lowline "Next low round number"
#define lowlinetradetrigger "Next sell trade trigger"
/*
void DisplayUserFeedback()
start()
----Trading functions----
void LookForTradingOpportunity()
bool SendSingleTrade(int type, string comment, double lotsize, double price, double stop, double TP, int magic)
bool DoesTradeExist()
----Matt's Order Reliable library code
bool O_R_CheckForHistory(int ticket) Cheers Matt, You are a star.
void O_R_Sleep(double mean_time, double max_time)
*/
extern string bs="----Basic stuff----";
extern double Lot=0.01;
extern int MagicNumber=615046;
extern string TradeComment="Round numbers";
extern bool CriminalIsECN=false;
extern int TradeTriggerPips=15;
extern bool ReverseTradeDirection=false;
extern bool TakeFirstTrade=true;
extern string tpsl="----Stop loss----";
extern int StopLoss=100;
extern string TSL="----Trailing stop loss----";
extern int TrailingStopPips=15;
extern int BreakEvenProfitPips=1;
extern string trs="----Odds and ends----";
extern int DisplayGapSize=30;
extern bool DeleteLinesOnExit=true;
extern double bprice=1.3480;
extern double sprice=1.3460;
double sl = 20;
double TP = 20;
//Matt's O-R stuff
int O_R_Setting_max_retries = 10;
double O_R_Setting_sleep_time = 4.0; /* seconds */
double O_R_Setting_sleep_max = 15.0; /* seconds */
//Round numbers
double RoundNumberHigh, RoundNumberHighTrigger;
double RoundNumberLow, RoundNumberLowTrigger;
//Misc stuff
string ScreenMessage, Gap;
bool RobotDisabled;
string DisabledMessage;
int Spread;
void DisplayUserFeedback()
{
ScreenMessage = "";
ScreenMessage = StringConcatenate(ScreenMessage, Gap, NL);
ScreenMessage = StringConcatenate(ScreenMessage, Gap, "Lot size = ", Lot, NL);
ScreenMessage = StringConcatenate(ScreenMessage, Gap, "Stop loss = ", StopLoss, NL);
ScreenMessage = StringConcatenate(ScreenMessage,Gap, "Magic number = ", MagicNumber, NL);
double spread = MarketInfo(Symbol(), MODE_SPREAD);
ScreenMessage = StringConcatenate(ScreenMessage, Gap, "Spread = ", spread, NL);
ScreenMessage= StringConcatenate(ScreenMessage, NL);
Comment(ScreenMessage);
}//void DisplayUserFeedback()
//+------------------------------------------------------------------+
//| expert Initialization function |
//+------------------------------------------------------------------+
int init()
{
int multiplier;
if(Digits == 2 || Digits == 4) multiplier = 1;
if(Digits == 3 || Digits == 5) multiplier = 10;
if(Digits == 6) multiplier = 100;
if(Digits == 7) multiplier = 1000;
TradeTriggerPips*= multiplier;
StopLoss*= multiplier;
BreakEvenProfitPips*= multiplier;
Gap="";
if (DisplayGapSize >0)
{
for (int cc=0; cc< DisplayGapSize; cc++)
{
Gap = StringConcatenate(Gap, " ");
}
}
Comment(".........Waiting for a tick");
start();
}
//+------------------------------------------------------------------+
//| expert Deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
Comment("");
}
bool DoesTradeExist()
{
//Searches for open trades
if (OrdersTotal() == 0) return(false); //nothing to do
bool found = false;
for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
{
if (!OrderSelect(cc, SELECT_BY_POS) ) continue;
if (OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() )
{
found = true;
if (OrderProfit() > 0) TrailingStopLoss();
}
}
return(found);
}//End bool DoesTradeExist()
bool SendSingleTrade(int type, string comment, double lotsize, double price, double sl, double TP, int magic)
{
int slippage = 10;
if (Digits == 3 || Digits == 5) slippage = 100;
color col = Red;
if (type == OP_BUY || type == OP_BUYSTOP) col = Green;
int expiry = 0;
//if (SendPendingTrades) expiry = TimeCurrent() + (PendingExpiryMinutes * 60);
if (!CriminalIsECN) int ticket = OrderSend(Symbol(),type, lotsize, price, slippage, sl, TP, comment, magic, expiry, col);
//Is a 2 stage criminal
if (CriminalIsECN)
{
ticket = OrderSend(Symbol(),type, lotsize, price, slippage, 0, 0, comment, magic, expiry, col);
if (sl != 0)
{
if (ticket > 0)
bool result = OrderModify(ticket, OrderOpenPrice(), sl, TP, 0, CLR_NONE);
if (!result)
{
int err=GetLastError();
Print(Symbol(), " ", type," SL order modify failed with error(",err,"): ",ErrorDescription(err));
}//if (!result)
}//if (Sl != 0)
}//if (CriminalIsECN)
//Error trapping for both
if (ticket < 0)
{
string stype;
if (type == OP_BUY) stype = "OP_BUY";
if (type == OP_BUYSTOP) stype = "OP_BUYSTOP";
if (type == OP_SELL) stype = "OP_SELL";
if (type == OP_SELLSTOP) stype = "OP_SELLSTOP";
err=GetLastError();
Alert(Symbol(), " ", stype," Manual EA order send failed with error(",err,"): ",ErrorDescription(err));
Print(Symbol(), " ", stype," Manual EA order send failed with error(",err,"): ",ErrorDescription(err));
return(false);
}//if (ticket < 0)
//Make sure the trade has appeared in the platform's history to avoid duplicate trades
O_R_CheckForHistory(ticket);
//Got this far, so trade send succeeded
return(true);
}//End bool SendSingleTrade(int type, string comment, double lotsize, double price, double stop, double TP)
//START TRADE LOGIC//
void LookForTradingOpportunity()
{
if (IsTradeContextBusy() ) return;
double sl, TP;
RefreshRates();
bool result;
double MinStop = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point;
if (!ReverseTradeDirection)
{
//Long
if(Bid >= bprice)
{
if (TakeFirstTrade)
{
//First trade with tp
result = false;
while (result == false)
{
if (StopLoss > 0) sl = NormalizeDouble(Ask - (StopLoss * Point), Digits);
result = SendSingleTrade(OP_BUY, TradeComment, Lot, Ask, sl, TP, MagicNumber);
}//while (result = false)
}//if (TakeFirstTrade)
}//
//Short
// if (Bid <= lo && Open[0] > lo && lo > 0)
if(Bid <= sprice)
{
if (TakeFirstTrade)
{
//First trade with tp
result = false;
while (!result)
{
if (StopLoss > 0) sl = NormalizeDouble(Bid + (StopLoss * Point), Digits);
result = SendSingleTrade(OP_SELL, TradeComment, Lot, Bid, sl, TP, MagicNumber);
}//While (!result)
}//if (TakeFirstTrade)
}//if (Bid <= lo && Open[1] > lo && lo > 0)
}//if (!ReverseTradeDirection)
}//void LookForTradingOpportunity()
//END TRADE LOGIC //
I am getting error 130 Invalid stops , where could i have gone wrong ??
when i set extern int StopLoss=0; all is fine in terms of orders getting fired except that no tp or sl values are put in along with the order .