Creating an EA That will Make Profits regardless of the trend direction, Timeframe and currency pair.

 
 I wanted an EA that will contually make a profit whether its an uptrend or a downtrend and to make the profit whether the candle is
 bullish or bearish. Now the problem is as soon as a candle opens on order opens as well depending on whether its a sell or buy and with
 each new order comes the current thread of the currency pair so each order opens on a negative so solution is to restrict the order open
 to 1 order per currency pair, I have restricted the number of orders that can open to 3 using the OrdersTotal() variable but this does
 not help much. Second problemis the placement of the stop-loss and take-profit if you place them too close the orders
 the orders keep hitting the SL/TP and closing there by allowing a new order to open which then starts on a negative thereby increasing
 the loss on your balance, but if you place them too far,you risk making a loss should the price change from a buy to sell or visa versa
 or the trend changes direction. So the solution is to place a TRAILLING-STOPwhich is a stop-loss that increases as the current price
 increases, this is what I am having a problem with.
 The good thing about this code is that it can work on any time frame or currency pair and response accurately to the price movement.
 
 The code is pretty simple,

(1) GET THE CURRENT PRICE OF THE CURRENT OPEN CANDLE
 
(2) GET THE INITIAL PRICE/OPENING PRICE OF THE CURRENT OPEN CANDLE, THE ASK PRICE IS ALWAYS LESS THAN THE BID PRICE BUT THEY ALWAYS MOVE CUN-CURRENTLY, MEANING WHEN THEY INCREASE
THEY INCREASE SIMULTANEOUSLY AND VISA VERSA,

(3) COMPARE THE CURRENT ASK PRICE TO THE INITIAL PRICE OF THE CURRENT CANDLE AND IF THE ASK PRICE IS GREATER THAN THE INIIAL PRICE
THEN YOU SHOULD OPEN A BUY ORDER AND IF THE ASK PRICE IS BELOW THE INITIAL PRICE YOU SHOULD OPEN A SELL ORDER,

int order;

void OnTick()
  {
// To be used for getting latest price quotes
   MqlTick Latest_Price; // Structure to get the latest prices     
   SymbolInfoTick(Symbol() ,Latest_Price); // Assign current prices to structure

// The BID price.
   static double dBid_Price;

// The ASK price.
   static double dAsk_Price;

   dBid_Price = Latest_Price.bid;  // Current Bid price.
   dAsk_Price = Latest_Price.ask;  // Current Ask price.
   double initialPrice = Open[0];  // Opening price of a candle

  
 
   if(OrdersTotal()<=3)        // restricts the number of orders to 3
   {
  
    if(dAsk_Price  > initialPrice){
   
    order = OrderSend(Symbol(),OP_BUY,0.02,dAsk_Price,3,dAsk_Price-200*_Point,dAsk_Price+40*_Point,NULL,0,0,NULL);} // Placing a buy order
     
    else if(dAsk_Price  < initialPrice){
  
    order = OrderSend(Symbol(),OP_SELL,0.02,dBid_Price,3,dBid_Price+200*_Point,dBid_Price-40*_Point,NULL,0,0,NULL);}//Placing a sell order
 
                       }

    }
 
20843712: THE ASK PRICE IS ALWAYS LESS THAN THE BID PRICE
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Don't SHOUT at us, that is RUDE.
  3. Ask is always higher than the Bid.

  4. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  5. 20843712: Now the problem is as soon as a candle opens on order opens as well d
    That is what your code says to do; buy if the second tick is above the first of a new bar. Fix your broken code to do what you want. Until you can state your criteria in concrete terms, it can't be coded.
    Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              PositionClose is not working - MQL5 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  6. 20843712 Second problemis the placement of the stop-loss and take-profit
    SL/TP has nothing to do with your initial loss. You have to pay the spread to open.

  7. 20843712: So the solution is to place a TRAILLING-STOP this is what I am having a problem with.
    You have no TSL code so you can't have a problem with it. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21