Conflict of logics .

 

i apologies for my subject topic .Am having trouble  with two pivotal logics of my  project  

here  is the code  i am to enter a trade if there is a squeeze of bollinger bands and a crossing of two moving averages, fastma or rma and slowma as yma    if the second crossing happens during a breakout happens of the bands we enter a trade but if the fast ma is to reach the value of 68 before it reaches the second crossing (tp breach) we councel the entry but look for another trade . And also if there is a loosing trade we are to wait until the fast ma reaches 68 before we can execute the trading conditions. so this is the order of the logic check for previously loosing trade  then for  the tpbreach this is where my challenge begins after a loosing trade the code nolonger checks for the tp breach .Thank you in advance.

logic in the ontict()

  if(BuySignal) //Bollinger bands squeeze
        {
         if(crossing1)
           {
            SqueezeBreakoutSig=true;
            drawVerticalLine("First crossing",candles[1].time,clrBlue);
            TpBreacgCount = 0; // Reset TpBreacgCount here
            // Reset previousTradeWasLoss if we're starting a new potential trade setup
            //  previousTradeWasLoss = false;
            //
           }
         //end of the BuySignal Condition
        }
        
      //all the other conditions should be executed after checking if there was a previously loosing positions
      if(previousTradeWasLoss&&BbandsBreakout)
        {
         Buy1signal=false;
         Buy2signal=false;

         if((MathFloor(rma[0])==68.0))
           {
            previousTradeWasLoss = false;
            Print("We can now enter new trades");

           }
        }
      
         if(!previousTradeWasLoss&&SqueezeBreakoutSig&&BbandsBreakout)
           {
            if((MathFloor(rma[0])==68.0))
              {
               TpBreacgCount ++;
               Print("TP_Level reached");
              }
              
            if(TpBreacgCount==0&&(crossing2))
              {
               Buy1signal=true;
              }
           }
code logic to check for previously loosing trades
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- get transaction type as enumeration value
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in history
   if(type==TRADE_TRANSACTION_DEAL_ADD)
     {
      ResetLastError();
      if(HistoryDealSelect(trans.deal))
         m_deal.Ticket(trans.deal);
      else
        {
         Print(__FILE__," ",__FUNCTION__,", ERROR: ","HistoryDealSelect(",trans.deal,") error: ",GetLastError());
         return;
        }
      if(m_deal.DealType()==DEAL_TYPE_BUY || m_deal.DealType()==DEAL_TYPE_SELL)
        {
         if(m_deal.Entry()==DEAL_ENTRY_OUT)
           {
            long position_id=m_deal.PositionId();
            if(HistorySelectByPosition(position_id))
              {
               uint     total = HistoryDealsTotal();
               ulong    ticket= 0;
               //--- for all deals
               for(uint i=0; i<total; i++)
                 {
                  //--- try to get deals ticket
                  if((ticket=HistoryDealGetTicket(i))>0)
                    {
                     //--- get deals properties
                     long     lng_time=HistoryDealGetInteger(ticket,DEAL_TIME);
                     datetime dat_time=(datetime)lng_time;
                     double   price    = HistoryDealGetDouble(ticket,DEAL_PRICE);
                     Print(dat_time,", ",DoubleToString(price,8));
                     if(m_deal.Profit()>0)
                       {
                        Print("Previously closed position was profitable");
                       }
                     else
                        if(m_deal.Profit()<0)
                          {
                           previousTradeWasLoss=true;
                           // waitingForLossConfirmation=false;
                           Print("Previously closed position was Loss");
                          }
                     position_Status= ("Profit: "+DoubleToString(m_deal.Profit())+"PosTicket: "+IntegerToString(ticket));
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+

//+----------------------------------------------------------
 
ZhuwaoAbel:

i apologies for my subject topic .Am having trouble  with two pivotal logics of my  project  

here  is the code  i am to enter a trade if there is a squeeze of bollinger bands and a crossing of two moving averages, fastma or rma and slowma as yma    if the second crossing happens during a breakout happens of the bands we enter a trade but if the fast ma is to reach the value of 68 before it reaches the second crossing (tp breach) we councel the entry but look for another trade . And also if there is a loosing trade we are to wait until the fast ma reaches 68 before we can execute the trading conditions. so this is the order of the logic check for previously loosing trade  then for  the tpbreach this is where my challenge begins after a loosing trade the code nolonger checks for the tp breach .Thank you in advance.

logic in the ontict()

code logic to check for previously loosing trades
So, what's the question or problem?


 
Dominik Egert #:
So, what's the question or problem?


okay the problem is that after a loosing trade the ea is nolonger able to identify the breach of the rma of the 68 level
 
ZhuwaoAbel #:
okay the problem is that after a loosing trade the ea is nolonger able to identify the breach of the rma of the 68 level
So, why could that be?

Maybe you want to printf-debug a bit why the ea stops opening new positions.
 
if(rma[0] >= 68.0)
if(rma[0] <= 68.0)

... maybe what is needed .. not == as that would mean it has to be the exact value

 
gardee005 #:

... maybe what is needed .. not == as that would mean it has to be the exact value

okay let  me try to re exlpain so here is whats happening without a loosing trade am able to check for breach of the tp level which i defined as 68 but after a loosing trade has been detected and the previoustradewasloss flag is turned false at 68 am no longer able to check for a tp breach its a counter loss system  it  enters trades resulting in more losses
 
ZhuwaoAbel #:
okay let  me try to re exlpain so here is whats happening without a loosing trade am able to check for breach of the tp level which i defined as 68 but after a loosing trade has been detected and the previoustradewasloss flag is turned false at 68 am no longer able to check for a tp breach its a counter loss system  it  enters trades resulting in more losses
Maybe it would be possible to see the problem if you share a compilable version of the code.
 
gardee005 #:

... maybe what is needed .. not == as that would mean it has to be the exact value

Thank you i , its here it should not be an exact figure so thank you the it worked,

if(rma[0] >= 68.0)
//i used 
(MathFloor(rma[0])>=68.0)

i only needed to change here and it worked thank you, Now  i can check for a previouslylosing trade then to check if there was a breach of the tp

Files: