Help with coding Slopey Crossy Bob with pending order

Post Reply
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Help with coding Slopey Crossy Bob with pending order

Post by fx800 »

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
You do not have the required permissions to view the files attached to this post.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Help with coding Slopey Crossy Bob with pending order

Post by SteveHopwood »

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:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Help with coding Slopey Crossy Bob with pending order

Post by fx800 »

Very kind of you to help. Will make the necessary changes and see if it works. Thanks again.
peter
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Help with coding Slopey Crossy Bob with pending order

Post by fx800 »

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.
You do not have the required permissions to view the files attached to this post.
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Help with coding Slopey Crossy Bob with pending order

Post by fx800 »

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.
Last edited by fx800 on Sat May 26, 2018 4:46 am, edited 1 time in total.
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Help with coding Slopey Crossy Bob with pending order

Post by fx800 »

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.
You do not have the required permissions to view the files attached to this post.
Bruster400
Trader
Posts: 192
Joined: Tue Sep 24, 2013 3:19 pm

Help with coding Slopey Crossy Bob with pending order

Post by Bruster400 »

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
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Help with coding Slopey Crossy Bob with pending order

Post by fx800 »

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

peter
You do not have the required permissions to view the files attached to this post.
User avatar
tomele
Administrator
Posts: 1208
Joined: Tue May 17, 2016 3:40 pm
Location: Germany, Forest of Odes, Defending the Limes

Help with coding Slopey Crossy Bob with pending order

Post by tomele »

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

Cheers
Happy pippin, Thomas :-BD

It ain't what you don't know that gets you into trouble.
It's what you know for sure that just ain't so.
(Mark Twain)

Keep the coder going: Donate
Post Reply

Return to “Coders Hangout”