How to convert a simple 2MA based to martingale.???

 
void OnTick()
  {
   if(MAPeriod1<MAPeriod2)
     {
      ArraySetAsSeries(ma1,true);
      ArraySetAsSeries(ma2,true);
      ArraySetAsSeries(close,true);
      CopyBuffer(maHandle1,0,0,1,ma1);
      CopyBuffer(maHandle2,0,0,1,ma2);
      CopyClose(_Symbol,0,0,1,close);
      // Trade structures
      MqlTradeRequest request;
      MqlTradeResult result;
      ZeroMemory(request);
      // Current position information
      bool openPosition = PositionSelect("EURUSDm#");
      long positionType = PositionGetInteger(POSITION_TYPE);
      ulong position_ticket=PositionGetTicket(0);
      if(ma2[0]<ma1[0])
        {
         // Open buy market order
         if(positionType==POSITION_TYPE_SELL)
            m_trade.PositionClose(position_ticket);
         if(openPosition==false || positionType==POSITION_TYPE_SELL)
           {
            ZeroMemory(request);
            request.action = TRADE_ACTION_DEAL;
            request.type = ORDER_TYPE_BUY;
            request.symbol = "EURUSDm#";
            request.volume = TradeVolume;
            request.type_filling = ORDER_FILLING_IOC;
            request.price = SymbolInfoDouble("EURUSDm#",SYMBOL_ASK);
            request.sl = 0;
            request.tp = 0;
            request.deviation = 50;
            OrderSend(request,result);
            request.position = result.order;
            // Modify SL/TP
            if(result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE)
              {
               request.action = TRADE_ACTION_SLTP;

               double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
               if(StopLoss > 0)
                  request.sl = positionOpenPrice - (StopLoss * _Point);
               if(TakeProfit > 0)
                  request.tp = positionOpenPrice + (TakeProfit * _Point);
               if(request.sl > 0 && request.tp > 0)
                  OrderSend(request,result);
              }
           }
        }
      if(ma2[0]>ma1[0])
        {
         if(positionType==POSITION_TYPE_BUY)
            m_trade.PositionClose(position_ticket);
         // Open sell market order
         if(openPosition == false|| positionType==POSITION_TYPE_BUY)
           {
            ZeroMemory(request);
            request.action = TRADE_ACTION_DEAL;
            request.type = ORDER_TYPE_SELL;
            request.symbol = "EURUSDm#";
            request.volume = TradeVolume;
            request.type_filling = ORDER_FILLING_IOC;
            request.price = SymbolInfoDouble("EURUSDm#",SYMBOL_ASK);
            request.sl = 0;
            request.tp = 0;
            request.deviation = 50;
            OrderSend(request,result);
            request.position = result.order;
            // Modify SL/TP
            if(result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE)
              {
               request.action = TRADE_ACTION_SLTP;
               double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
               if(StopLoss > 0)
                  request.sl = positionOpenPrice - (StopLoss * _Point);
               if(TakeProfit > 0)
                  request.tp = positionOpenPrice + (TakeProfit * _Point);
               if(request.sl > 0 && request.tp > 0)
                  OrderSend(request,result);
              }
           }
        }
     }
  }

Help me convert something as simple as this code to martingale.....

Or get me the simplest martingale EA whose code can be used to learn this strategy..???


I know the basics algorithm, I am just unable to code it.

I tried searching but most of them are too advanced to learn from.


Please help. thanks.

 
saurabhsuman003:

Help me convert something as simple as this code to martingale.....

Or get me the simplest martingale EA whose code can be used to learn this strategy..???

I know the basics algorithm, I am just unable to code it.

  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help (2017)

  2. Do your own research.

  3. MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  4. or pay (Freelance) someone to code it. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2019)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
              No free help (2017)

  5. Hedging, grid trading, same as Martingale.
              Martingale, Hedging and Grid : MHG - General - MQL5 programming forum (2016)

    Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
              Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum (2015)

    Why it won't work:
              Calculate Loss from Lot Pips - MQL5 programming forum (2017)
              THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube (2020.12.12)

 
William Roeder #:
  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.

Brother.... I need statements to know if previously closed trade was loss or profit.

and I will combine it with a conditionally resettable counter variable to change the volume of next trade.

This variable will increase by a linear or exponential factor if the last trade was loss and will reset to the base value if last trade was profit.


thanks brother. pls help.

if(last trade = profit)
trade volume=base value;
if(last trade = loss)
trade volume=trade volume*2;

just a line for how to get profit or los of last trade.

 

Hello

Try this:

//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
        if( trans.symbol ==_Symbol )  
          if( trans.type == TRADE_TRANSACTION_DEAL_ADD )    
            if ( HistoryDealGetInteger(trans.deal,DEAL_ENTRY) != DEAL_ENTRY_IN )
              if ( HistoryDealGetDouble(trans.deal,DEAL_PROFIT) > 0 ) 
                                { /*trade volume=base value;*/}
              else
              if ( HistoryDealGetDouble(trans.deal,DEAL_PROFIT) < 0 ) 
                                { /*trade volume=trade volume*2;*/}
  }

Good luck

 
galafron #:

Hello

Try this:

Good luck

I was looking more to apply this.

hadn't ever used any history base commands.

Struggled finding the fact that we have to select a period of history using HistorySelect().

Then i inserted the whole set of statements into ontick() and now its working perfectly.

Thanks.