#property copyright "Copyright © 2008, AKA TradeForexFX" #property link "http://www./" extern string Expert_Name = "Three Level TP Beta"; extern int MagicNumber = 57006; extern double Lots = 1.5; extern bool Close_Lots_Mode = True; extern double First_Close = 0.5 ; extern int First_Close_TP = 30 ; extern double Second_Close = 0.5 ; extern int Second_Close_TP = 50 ; extern double Third_Close = 0.5 ; extern int Third_Close_TP = 100 ; extern int Slippage = 3; //****************************************** // Trading Hours variables end here //************************************ //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int Total; Total = OrdersTotal(); //+------------------------------------------------------------------+ //| Variable Begin | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Variable End | //+------------------------------------------------------------------+ //Check position bool IsTrade = False; for (int i = 0; i < Total; i ++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //******************************************* // Important to have code check MagicNumber and Symbol if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != MagicNumber) continue; //******************************************* if(OrderType() <= OP_SELL) { IsTrade = True; if(OrderType() == OP_BUY) { //+------------------------------------------------------------------+ //| Signal Begin(Exit Buy) | //+------------------------------------------------------------------+ double QtyOrders = 0.00; QtyOrders = CalculateQtyIntoTrade(); //+------------------------------------------------------------------+ //| Signal End(Exit Buy) | //+------------------------------------------------------------------+ //Close_Lots - Buy if(Close_Lots_Mode && (QtyOrders - (Second_Close + Third_Close)) > 0.00) { if(Bid - OrderOpenPrice() > Point * First_Close_TP) { OrderClose(OrderTicket(), (QtyOrders - (Second_Close + Third_Close)) , Bid, Slippage, MediumSeaGreen); continue; } } if(Close_Lots_Mode && ((QtyOrders - (Third_Close)) > 0.00 ) &&((QtyOrders - (Second_Close + Third_Close ) < 0.00) || (QtyOrders - (Second_Close + Third_Close) == 0.00 ))) { if(Bid - OrderOpenPrice() > (Point * Second_Close_TP)) { OrderClose(OrderTicket(), (QtyOrders - Third_Close) , Bid, Slippage, MediumSeaGreen); continue; } } if(Close_Lots_Mode && (QtyOrders - Third_Close == 0.00 ) || (QtyOrders - Third_Close < 0.00 ) && (QtyOrders > 0.00 )) { if(Bid - OrderOpenPrice() > Point * Third_Close_TP) { OrderClose(OrderTicket(), QtyOrders , Bid, Slippage, MediumSeaGreen); continue; } } } else { //Close_Lots - Sell double QtyOrderSells = 0.00; QtyOrderSells = CalculateQtyIntoTrade(); Comment ( "Quantity in trade - Buys ", QtyOrders, "\n", "Quantity in trade - Sells", QtyOrderSells, "\n", "Initial Order Quantity", OrderLots(), "\n", "CalculateQtyIntoTrade", CalculateQtyIntoTrade() ); if(Close_Lots_Mode && (QtyOrderSells - (Second_Close + Third_Close)) > 0.00) { if(OrderOpenPrice() - Ask > Point * First_Close_TP) { OrderClose(OrderTicket(), (QtyOrderSells - (Second_Close + Third_Close)) , Bid, Slippage, MediumSeaGreen); continue; } } if(Close_Lots_Mode && ((QtyOrderSells - (Third_Close)) > 0.00 ) &&((QtyOrderSells - (Second_Close + Third_Close ) < 0.00) || (QtyOrderSells - (Second_Close + Third_Close) == 0.00) )) { if(OrderOpenPrice() - Ask > (Point * Second_Close_TP)) { OrderClose(OrderTicket(), (QtyOrderSells - Third_Close) , Bid, Slippage, MediumSeaGreen); continue; } } if(Close_Lots_Mode && (QtyOrderSells - Third_Close == 0.00 ) || (QtyOrderSells - Third_Close < 0.00 ) && (QtyOrderSells > 0.00 )) { if(OrderOpenPrice() - Ask > Point * Third_Close_TP) { OrderClose(OrderTicket(), QtyOrderSells , Bid, Slippage, MediumSeaGreen); continue; } } } } } } double CalculateQtyIntoTrade() { double xnum = 0.00; for(double j=0.00 ;j