Job finished
Specification
1. how to find the martingale level after a closing and reopening
2. How implement break even (template code)
I have this params:
input string s1 = "Last update: 2017/10/11";
input bool UseMoneyManagement = false; //UseMoneyManagement use money management for the trade volume calculation
input double RiskPercent = 0.5; //RiskPercent the percent of the risk for the trade volume calculation
input double Lots = 0.01; //Lots fixed lot size
input int NBarsCalcStopLoss = 4; //NBarsCalcStopLoss The n. bars for calc Higest (for sell) or Lowest (for buy)
input double GapStopLoss = 5; //GapStopLoss To be added to StopLoss
input double RRTakeProfit = 1.0; //RRTakeProfit Rsk Reward for calc Take profit
input int MagicNumber = 1122112223;//Magic number for EA's orders
input int Slippage = 70; //Slippage maximum allowed deviation (in pips) of the price by opening
input int SpreadLimit = 12; //SpreadLimit maximum allowed spread in points
// input int StrategyN = 3; //number of case in FcStrategy.MA routine that is the strategy used to determine the buy or sell
input string s2 = "-------------------";
input int FromTimeHourTrade = 6; // Hour from start trade
input int ToTimeHourTrade = 19; // Hour to stop trade
input int MaxBarsStillTradeOpen= 10; // Max number of bars where position can be open, after this the operation is closed
input int PercOfGainForBE = 0; // PercOfGainForBE (0=Disalbed) The percentage of gain for apply Break even
input int PercOfLotsToCloseAtBE= 50; // The percetange of lots to be close when the PercOfGainForBE is reached
input string s3 = "-------------------";
input double MultiplierLot = 2.0;
input double MaxLots = 1.28;
input string ContRev = "RCCRCRRCCCRRC"; //C=Continue; R=Reverse; Continue is the versus of first (lose) trade, Reverse is the opposite versus of first (lose) trade
this routine menage break even but don't work
//+--------------------------------------------------------------------------------+
//| the function for managing of EA's Break even and max bars trade |
//+--------------------------------------------------------------------------------+
void do_manageBE( int magicBuySell)
{
int typ;double lot=0;double profit;
double tmpLots=0;
int BuyOrSell=0;
double point = XGetPoint(Symbol()); // get point value
int total_ordersB = orders_count(MagicNumber); // count of opening orders
int total_ordersS = orders_count(MagicNumber); // count of opening orders
string symbol = Symbol();
//
//--- Check the action to do based on the last trade result
//
if(((total_ordersB+total_ordersS) > 0) ){ // Check One order active
if(nBSOT.LastStartHour!=Time[0]){ // Check for increment n. of bar trade is active
// Moved to History() routine --- nBSOT.nBarsStillOpenTrade=iBarShift(NULL,0,OrderOpenTime(),true);//++;
nBSOT.LastStartHour=Time[0];
}
//
// Manage n. max of bar where the trade must be opened
//
if((nBSOT.nBarsStillOpenTrade>MaxBarsStillTradeOpen) && (MaxBarsStillTradeOpen>0)){ // Check the numer of hour active trade exceed the threeshold
int orders_total = OrdersTotal(); // Num. tot. orders
for( int count = 0; count < orders_total; count++ ){ // Cicle for orders
if( OrderSelect(count,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber() == MagicNumber ){ // if selected order is active trade and magic ok
// Print("Close..."+OrderTicket()+":-:"+OrderLots()+":-:"+Bid+":-:"+nBSOT.nBarsStillOpenTrade);
int ord_type = OrderType();
double PriceForClose=0.0;
if( ord_type == OP_BUY )
PriceForClose=Bid;
if( ord_type == OP_SELL )
PriceForClose=Ask;
XOrderClose(OrderTicket(), OrderLots(), PriceForClose, Slippage); // Close order
}
}
}
//
// Manage Break Even
//
if((PercOfGainForBE>0)){ // Check the break even required by user input
int orders_total = OrdersTotal(); // Num. tot. orders
for( int count2 = 0; count2 < orders_total; count2++ ){ // Cicle for orders
if( OrderSelect(count2,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber() == MagicNumber ){ // if selected order is active trade and magic ok
// Print("Close..."+OrderTicket()+":-:"+OrderLots()+":-:"+Bid+":-:"+nBSOT.nBarsStillOpenTrade);
int ord_type = OrderType();
double PriceForClose=0.0;
if( ord_type == OP_BUY ){
PriceForClose=0.0;
if(Bid>=LastTradeBE){ // Check if the LastTradeBE (setted at the order open) is more than Bid price
PriceForClose=Bid; // is time to close order
}
}
if( ord_type == OP_SELL ){
PriceForClose=0.0;
if(Ask<=LastTradeBE){ // Check if the LastTradeBE (setted at the order open) is less than Ask price
PriceForClose=Ask; // is time to close order
}
}
if(PriceForClose>0.0){
XOrderModify(OrderTicket(),PriceForClose,OrderOpenPrice(),OrderTakeProfit(),0,0); // Modify SL to entry price (Break Even)
//if(PercOfLotsToCloseAtBE>0){
// XOrderClose(OrderTicket(), ActualTradePercOfLotsToCloseAtBE, PriceForClose, Slippage);
// return;
//}
// XOrderClose(OrderTicket(), OrderLots(), PriceForClose, Slippage); // Close order
}
}
}
}
}