stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Help with coding Slopey Crossy Bob with pending order
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5465
Page 1 of 1
Author:  fx800 [ Tue May 22, 2018 12:18 am ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

Hi
I would be very grateful if someone can have a look at the code for SCB with pending order attached below. The codes look ok but the ea is not sending any trades even when all the conditions are fulfilled.

Code: Select all

   //Long 
   if (SendLong)
   {
      CountOpenTrades(symbol, PairIndex);
      if (MarketBuysCount > 0)
         return;
         
      if (BuyStopsCount > 0)
         return;   
       
       type = OP_BUYSTOP;
       
       price = NormalizeDouble(Ask + (PendingOrderBuffer/factor), Digits);
        
       //if ((price - Ask) <= (PendingOrderBuffer / factor)) price = price + (PendingOrderBuffer / factor); //increase if price too close to current high
       if ((Ask + stopLevel) >= price ) return;//MR LONG MOD
         
      stop = CalculateStopLoss(OP_BUY, price);
         
         
      take = CalculateTakeProfit(OP_BUY, price);
      
      
      //Lot size calculated by risk
      if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop );

               
      SendTrade = true;
      
   }//if (SendLong)
   
   //Short
   if (SendShort)
   {
      CountOpenTrades(symbol, PairIndex);
      if (MarketSellsCount > 0)
         return;
      
      if (SellStopsCount > 0)
         return;
         
       type = OP_SELLSTOP;  
      
       price = NormalizeDouble(Bid - (PendingOrderBuffer/factor), Digits);
        
       //if ((Bid - price) <= (PendingOrderBuffer / factor)) price = price - (PendingOrderBuffer / factor); //decrease if price too close to current low
       if (price >= (Bid - stopLevel)) return;//MR LONG MOD

      stop = CalculateStopLoss(OP_SELL, price);
         
      take = CalculateTakeProfit(OP_SELL, price);
      
      
      //Lot size calculated by risk
      if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop);

      
         
      SendTrade = true;      
   
      
   }//if (SendShort)

Code: Select all

   //Buy
   if (tradingStatus[PairIndex] == tradablelong)
      if (MarketBuysCount == 0)
         if (BuyStopsCount == 0)
      {
         SendTrade = true;
         type = OP_BUYSTOP;
         price = NormalizeDouble(Ask + (PendingOrderBuffer/factor), Digits);
         
       //if ((price - Ask) <= (PendingOrderBuffer / factor)) price = price + (PendingOrderBuffer / factor); //increase if price too close to current high
       if ((Ask + stopLevel) >= price ) return;//MR LONG MOD
         
         if (UseZeljko && !BalancedPair(symbol, OP_BUY) ) return;
         
         stop = CalculateStopLoss(OP_BUY, price);
         
         
         take = CalculateTakeProfit(OP_BUY, price);
         
         
         //Lot size calculated by risk
         if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop);
         
      }//if (!DoesTradeExist(symbol, OP_BUY) )
      
   //Sell
   if (tradingStatus[PairIndex] == tradableshort)
      if (MarketSellsCount == 0)
         if (SellStopsCount ==0 )
      {
         SendTrade = true;
         type = OP_SELLSTOP;
         price = NormalizeDouble(Bid - (PendingOrderBuffer/factor), Digits);
         
       //if ((Bid - price) <= (PendingOrderBuffer / factor)) price = price - (PendingOrderBuffer / factor); //decrease if price too close to current low
       if (price >= (Bid - stopLevel)) return;//MR LONG MOD
         
         if (UseZeljko && !BalancedPair(symbol, OP_SELL) ) return;
         
         stop = CalculateStopLoss(OP_SELL, price);
         
         
         take = CalculateTakeProfit(OP_SELL, price);
         
         
         //Lot size calculated by risk
         if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop);
         
      }//if (!DoesTradeExist(symbol, OP_SELL) )
Thank you in advance.
peter
Author:  SteveHopwood [ Wed May 23, 2018 11:17 pm ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

fx800 » Tue May 22, 2018 12:18 am wrote:Hi
I would be very grateful if someone can have a look at the code for SCB with pending order attached below. The codes look ok but the ea is not sending any trades even when all the conditions are fulfilled.

Code: Select all

   //Long 
   if (SendLong)
   {
      CountOpenTrades(symbol, PairIndex);
      if (MarketBuysCount > 0)
         return;
         
      if (BuyStopsCount > 0)
         return;   
       
       type = OP_BUYSTOP;
       
       price = NormalizeDouble(Ask + (PendingOrderBuffer/factor), Digits);
        
       //if ((price - Ask) <= (PendingOrderBuffer / factor)) price = price + (PendingOrderBuffer / factor); //increase if price too close to current high
       if ((Ask + stopLevel) >= price ) return;//MR LONG MOD
         
      stop = CalculateStopLoss(OP_BUY, price);
         
         
      take = CalculateTakeProfit(OP_BUY, price);
      
      
      //Lot size calculated by risk
      if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop );

               
      SendTrade = true;
      
   }//if (SendLong)
   
   //Short
   if (SendShort)
   {
      CountOpenTrades(symbol, PairIndex);
      if (MarketSellsCount > 0)
         return;
      
      if (SellStopsCount > 0)
         return;
         
       type = OP_SELLSTOP;  
      
       price = NormalizeDouble(Bid - (PendingOrderBuffer/factor), Digits);
        
       //if ((Bid - price) <= (PendingOrderBuffer / factor)) price = price - (PendingOrderBuffer / factor); //decrease if price too close to current low
       if (price >= (Bid - stopLevel)) return;//MR LONG MOD

      stop = CalculateStopLoss(OP_SELL, price);
         
      take = CalculateTakeProfit(OP_SELL, price);
      
      
      //Lot size calculated by risk
      if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop);

      
         
      SendTrade = true;      
   
      
   }//if (SendShort)

Code: Select all

   //Buy
   if (tradingStatus[PairIndex] == tradablelong)
      if (MarketBuysCount == 0)
         if (BuyStopsCount == 0)
      {
         SendTrade = true;
         type = OP_BUYSTOP;
         price = NormalizeDouble(Ask + (PendingOrderBuffer/factor), Digits);
         
       //if ((price - Ask) <= (PendingOrderBuffer / factor)) price = price + (PendingOrderBuffer / factor); //increase if price too close to current high
       if ((Ask + stopLevel) >= price ) return;//MR LONG MOD
         
         if (UseZeljko && !BalancedPair(symbol, OP_BUY) ) return;
         
         stop = CalculateStopLoss(OP_BUY, price);
         
         
         take = CalculateTakeProfit(OP_BUY, price);
         
         
         //Lot size calculated by risk
         if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop);
         
      }//if (!DoesTradeExist(symbol, OP_BUY) )
      
   //Sell
   if (tradingStatus[PairIndex] == tradableshort)
      if (MarketSellsCount == 0)
         if (SellStopsCount ==0 )
      {
         SendTrade = true;
         type = OP_SELLSTOP;
         price = NormalizeDouble(Bid - (PendingOrderBuffer/factor), Digits);
         
       //if ((Bid - price) <= (PendingOrderBuffer / factor)) price = price - (PendingOrderBuffer / factor); //decrease if price too close to current low
       if (price >= (Bid - stopLevel)) return;//MR LONG MOD
         
         if (UseZeljko && !BalancedPair(symbol, OP_SELL) ) return;
         
         stop = CalculateStopLoss(OP_SELL, price);
         
         
         take = CalculateTakeProfit(OP_SELL, price);
         
         
         //Lot size calculated by risk
         if (!CloseEnough(RiskPercent, 0)) SendLots = CalculateLotSize(symbol, price, stop);
         
      }//if (!DoesTradeExist(symbol, OP_SELL) )
Thank you in advance.
peter
It looks to me as though you have found the reason that SCB failed in the first place - and it is all my fault so do not feel bad about being unable to make your pending orders go. Using your file, look at lines 153-154:
double ask=0, bid=0, spread=0;//Replaces Ask. Bid, Digits. factor replaces Point
int digits;//Replaces Digits.

SCB is a multi-pair trader, so ask replaces Ask and can be used throughout the program. Ditto bid for Bid etc.

Then go to line 1776 and the void GetBasics(string symbol) function. This is called whenever ask, bid, spread and digits need populating.

By the time void LookForTradingOpportunities(string symbol, int PairIndex) is called, bid, ask, spread and digits should all have the correct values.

Now look at line 3757:
price = NormalizeDouble(Ask + (PendingOrderBuffer/factor), Digits);

This should clearly be:
price = NormalizeDouble(ask + (PendingOrderBuffer/factor), digits);


Then look at line 3789:
price = NormalizeDouble(Bid - (PendingOrderBuffer/factor), Digits);


This clearly should be:
price = NormalizeDouble(bid - (PendingOrderBuffer/factor), digits);

Looking at line 3761 I see another 'Ask' that should be 'ask'. At line 3792 I see another 'Bid' that should be 'bid'.

Can you do me a favour please? It is past midnight here and I am going to bed - plus the single malt has been good tonight. :lol: I have a busy teaching day tomorrow so the earliest I can get around to posting an updated version is Friday, so better to wait until the weekend. Could you make the changes please, and let me know if they work?

Maybe SCB failed because I am an idiot. You might be responsible for his resurgence.

:xm: :rocket:
Author:  fx800 [ Wed May 23, 2018 11:22 pm ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

Very kind of you to help. Will make the necessary changes and see if it works. Thanks again.
peter
Author:  fx800 [ Wed May 23, 2018 11:35 pm ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

fx800 » Wed May 23, 2018 11:22 pm wrote:Very kind of you to help. Will make the necessary changes and see if it works. Thanks again.
peter
The amended version posted below. Waiting to see if it works.

Exciting times ahead.
Author:  fx800 [ Thu May 24, 2018 2:27 am ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

fx800 » Wed May 23, 2018 11:35 pm wrote:
fx800 » Wed May 23, 2018 11:22 pm wrote:Very kind of you to help. Will make the necessary changes and see if it works. Thanks again.
peter
The amended version posted below. Waiting to see if it works.

Exciting times ahead.
Author:  fx800 [ Thu May 24, 2018 5:43 am ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

fx800 » Wed May 23, 2018 11:35 pm wrote:
fx800 » Wed May 23, 2018 11:22 pm wrote:Very kind of you to help. Will make the necessary changes and see if it works. Thanks again.
peter
The amended version posted below. Waiting to see if it works.

Exciting times ahead.
I am quite puzzled by the ea still not sending any pending order. Chart attached below for AUDUSD H4 and AUDCAD H4. No error messages either.
Author:  Bruster400 [ Thu May 24, 2018 8:28 am ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

fx800 » Thu May 24, 2018 6:43 am wrote:
fx800 » Wed May 23, 2018 11:35 pm wrote:
I am quite puzzled by the ea still not sending any pending order.
Easiest (if there is such a thing!) was is to use a debug tool - I use MetaEditor's (ME). Open a demo account and launch ME from it. Then, in ME, go to Tools/Options/Debug tab and fill in the details of where and when you want to test - make sure your demo has history for that period.

Then open the EA code in ME and from the Debug menu select "Start on Real Data" (F5). This will load the EA to a chart in your demo account. Make sure live trading etc are ticked as you would with loading to a normal chart. The chart will be loaded with debug.tpl as its template so you can change this if needed.

Once it's loaded up, go to ME (handy to have two screens...) and you can start to drop in breakpoints to pause the code at points where you want to check things and you can add variables to "watch" which means that you'll see their values / states at each breakpoint. You then just step the EA through its paces using the navigation buttons - play, pause, step into etc.

If you're watching the right things at the right time in the code then you should find the issue..... eventually. :-)

It's not the best but it's a whole lot better than trying to keep track of what is going on as you read through the code.

Hope that helps

Bruster
Author:  fx800 [ Fri May 25, 2018 6:26 am ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

The attached ea is now working. Thank you very much Steve.

peter
Author:  tomele [ Fri May 25, 2018 9:03 pm ]
Post subject:  Help with coding Slopey Crossy Bob with pending order

fx800 wrote:The attached ea is now working
... and now has a different database identifier as it should.

Cheers
All times are UTC Page 1 of 1