Hello,
I have two scripts to buy or sell two orders with the same stop loss and different take profit. The only problem is my account has to comply with US FIFO rules and when the market is very volatile these two orders will not get filled because it violates these rules at the Stop Loss level. What happens is as the market moves fast up and down the second order might get filled a couple of pippets later, let’s say if I’m going short on EURUSD and if I put a stop of 20 pips on the sell script and I get filled with the first order at 1.14000 and filled at 1.13998 for my second order on the script it will violate because it will try to put a stop for the second order at 1.14198 because the first order is already at 1.14200 for the stop loss and the second order can’t close first than the second. So I was wondering if someone could help me fixing this problem by forcing the second order to have the same stop loss as the first order.
Code for the buy script:
#property show_inputs
#include <stderror.mqh>
#include <stdlib.mqh>
//parameternya ini, input-nya ini
extern double LOT = 0.30;
extern int TP = 20;
extern int TP2 = 60;
extern int SL = 20;
//---------------------------
string MySym = "";
int MyDigits = 5;
double MyPoints = 0.0001;
//+------------------------------------------------------------------+
//| Custom initialization function |
//+------------------------------------------------------------------+
int init()
{
MySym = Symbol();
MyPoints = MarketInfo( MySym, MODE_POINT );
MyDigits = MarketInfo( MySym, MODE_DIGITS );
//---
if( MyPoints == 0.001 ) { MyPoints = 0.01; MyDigits = 3; }
else if( MyPoints == 0.00001 ) { MyPoints = 0.0001; MyDigits = 5; }
return(0);
}
//+------------------------------------------------------------------+
// +
//+------------------------------------------------------------------+
int start()
{
RefreshRates();
while( IsTradeContextBusy() ) { Sleep(100); }
//----
double Stop = NormalizeDouble(Ask - (SL * MyPoints),MyDigits);
double Prof1 = NormalizeDouble(Ask + (TP * MyPoints),MyDigits);
double Prof2 = NormalizeDouble(Ask + (TP2 * MyPoints),MyDigits);
int ticket = OrderSend(MySym,OP_BUY,LOT,Ask,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof1,"contest",1,0,CLR_NONE);
OrderSend(MySym,OP_BUY,LOT,Ask,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof2,"contest",2,0,CLR_NONE);
if(ticket<1)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
return;
}
//----
OrderPrint();
return(0);
}
Code for the sell script:
#property show_inputs
#include <stderror.mqh>
#include <stdlib.mqh>
//parameternya ini, input-nya ini
extern double LOT = 0.30;
extern int TP = 20;
extern int TP2 = 60;
extern int SL = 20;
//---------------------------
string MySym = "";
int MyDigits = 5;
double MyPoints = 0.0001;
//+------------------------------------------------------------------+
//| Custom initialization function |
//+------------------------------------------------------------------+
int init()
{
MySym = Symbol();
MyPoints = MarketInfo( MySym, MODE_POINT );
MyDigits = MarketInfo( MySym, MODE_DIGITS );
//---
if( MyPoints == 0.001 ) { MyPoints = 0.01; MyDigits = 3; }
else if( MyPoints == 0.00001 ) { MyPoints = 0.0001; MyDigits = 5; }
return(0);
}
//+------------------------------------------------------------------+
// +
//+------------------------------------------------------------------+
int start()
{
RefreshRates();
while( IsTradeContextBusy() ) { Sleep(100); }
//----
double Stop = NormalizeDouble(Bid + (SL * MyPoints),MyDigits);
double Prof1 = NormalizeDouble(Bid - (TP * MyPoints),MyDigits);
double Prof2 = NormalizeDouble(Bid - (TP2 * MyPoints),MyDigits);
int ticket = OrderSend(MySym,OP_SELL,LOT,Bid,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof1,"contest",1,0,CLR_NONE);
OrderSend(MySym,OP_SELL,LOT,Bid,NormalizeDouble(3 * MyPoints,MyDigits),Stop,Prof2,"contest",2,0,CLR_NONE);
if(ticket<1)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
return;
}
//----
OrderPrint();
return(0);
}
Thanks