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

My shell EA code
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=79
Page 20 of 23
Author:  DigitalCrypto [ Wed Jul 19, 2017 9:48 am ]
Post subject:  My shell EA code

Hey Steve,

EDIT: Forgot to mention this is USA FIFO non-counter trading crims.

I have a question regarding the trade signals that I can't seem to wrap my head around.

I want to do two things with one trade signal at the same time or more precisely I want to close a trade and then open the opposite trade.

For example if Condition Sell signal arrives can we do a BuyCloseSignal=true then on next line SellSignal = true?

Here's my code

Code: Select all

      //+------------------------------------------------------------------+
      //|   Begin Buy/Sell Signals                                         |
      //+------------------------------------------------------------------+
      //Buy signal
      if(S3LongSignal)
         if(ObjectFind(S1BuyLineName)>-1)//There is a buy line
            if(iOpen(Symbol(),TradingTimeFrame,1) < S1BuyLinePrice)//Open < BuyLinePrice
               if(iClose(Symbol(),TradingTimeFrame,1) > S1BuyLinePrice)//Cross upwards of the buy line
                  {
                     SellCloseSignal   = True; //First close any sells that are open
                     BuySignal         = True; //Second open a buy trade       
                  }

      //Buy signal
      if(S2LongSignal)
         if(ObjectFind(S1BuyLineName)>-1)//There is a buy line
            if(iOpen(Symbol(),TradingTimeFrame,1) < S1BuyLinePrice)//Open < BuyLinePrice
               if(iClose(Symbol(),TradingTimeFrame,1) > S1BuyLinePrice)//Cross upwards of the buy line
                  {
                     SellCloseSignal   = True; //First close any sells that are open
                     BuySignal         = True; //Second open a buy trade       
                  }
This should work shouldn't it?

Appreciate your sage advice
David
Author:  SteveHopwood [ Wed Jul 19, 2017 10:07 am ]
Post subject:  My shell EA code

DigitalCrypto » Wed Jul 19, 2017 9:48 am wrote:Hey Steve,

I have a question regarding the trade signals that I can't seem to wrap my head around.

I want to do two things with one trade signal at the same time or more precisely I want to close a trade and then open the opposite trade.

For example if Condition Sell signal arrives can we do a BuyCloseSignal=true then on next line SellSignal = true?

This should work shouldn't it?

Appreciate your sage advice
David
Yes. Make sure that ReadIndicatorValues() is called before CountOpenTrades() and you can use this construct:

Code: Select all

if (some condition)
      if (another condition)
      {
              SellSignal = true;
              BuyCloseSignal = true;
      }
CountOpenTrades() calls LookForTradeClosure(), which spots the BuyCloseSignal and closes buy trades.

:xm:
Author:  DigitalCrypto [ Wed Jul 19, 2017 11:19 am ]
Post subject:  My shell EA code

Yep Steve much appreciated!

I'm using your default OnTick() function

I've actually got a setup happening right this moment on EU. So I will check to make sure it works, IF it (the trade signal) happens of course.


EDIT: Looking back through OnTick() I spotted the part where you noted

Code: Select all

ReadIndicatorValues();//This might want moving to the trading section at the end of this function if EveryTickMode = false
So I went ahead and put that at the end of the function just before the DisplayUserFeedback() update bit. Now just need to sit on my hands and wait for conditions to arrive. :clap:
Author:  SteveHopwood [ Sun Sep 17, 2017 3:52 pm ]
Post subject:  My shell EA code

There are updates to the first five shells in post 1. I have gradually refined them as use threw up errors and places where there could be some improvement. I have also added Thomas' display refinements along with things such as replacing OrderSelect() with his BetterOrderSelect().

I have updated the Nuclear Option script. I have added the facility to use -1 as a 'kill all trades whatever their magic number is'. The script will ignore magic numbers when its own is -1. A magic of 0 still means manual trades and a magic of >0 will still cause manual trades to be ignored.

:xm:
Author:  SteveHopwood [ Sun Oct 01, 2017 1:57 pm ]
Post subject:  My shell EA code

Updated versions of my shells are in post 1, in the zip file. Along with correcting errors that cropped up with use I have added functions such as Tommaso's pip factor and Thomas' BetterOrderSelect().

:xm:
Author:  SteveHopwood [ Sat Dec 09, 2017 7:56 pm ]
Post subject:  My shell EA code

I have added a new zip to post 1 - "Shell codes updated 9th Dec 2017.zip"

It contains updates to the shells that I have been making as using them has highlighted code that needed attention.

I have made substantial changes to the Bbo-stuff versions. I am no longer being asked to code Slope, CSS or RSI-TMA Slope.

I have replaced them with the indi's that most of us are using these days - HGI and SuperSlope. Code for the original indis is still in the original zip file and that is still available in post 1. We can always return to these if need be.

I recently had to code an EA for a member that involved trading sessions not necessarily starting exactly on the hour and I wanted to use Baluda's trading hours for this purpose, and to draw a vertical line at the start of the trading session and an open price trendline. It took me a while to work out how to do this so I do not want to lose it; I have added the code to the shells as an additional graphical feature.

:xm:
Author:  DigitalCrypto [ Sun Dec 10, 2017 1:08 am ]
Post subject:  My shell EA code

Awesome Steve! Do you plan on keeping the originals up here for a while or will they be removed at some point?
Author:  SteveHopwood [ Sun Dec 10, 2017 1:23 am ]
Post subject:  My shell EA code

DigitalCrypto » Sun Dec 10, 2017 1:08 am wrote:Awesome Steve! Do you plan on keeping the originals up here for a while or will they be removed at some point?
I plan leaving old zip files in post 1. Experience has taught me that I never know when someone might ask for something old again - or that I need it and can no longer find it.

I forgot to mention that the shell user guide in post 1 refers to the older code in the original zip file. The user guide that refers to the latest version is in the 9th Dec 2017 zip.

This seems to me like an excellent way to move forward with these shells. They will evolve with time so we can have both what is current and retain access to what happened formerly. Also, I do not have to keep 60,000 versions of them on my computer.

:xm:
Author:  SteveHopwood [ Sat Jan 06, 2018 11:40 am ]
Post subject:  My shell EA code

I have added a new zipfile to post 1, containing two combined dashboard and multi-pair EA shells. I have included a PDF to explain where to add your own code.

:xm:
Author:  SteveHopwood [ Mon Jan 08, 2018 9:13 am ]
Post subject:  My shell EA code

I created Slopey Crossy Bob and Slopey Bob's Grid from the combined dashboard/autotrader shells, so they both need the LotsPerDollopOfCash code adding.

Add this function:

Code: Select all

void CalculateLotAsAmountPerCashDollops()
{

   double lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
   int decimal = 0;
   if (CloseEnough(lotstep, 0.1) )
      decimal = 1;
   if (CloseEnough(lotstep, 0.01) )
      decimal = 2;
      
   double maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
   double minlot = MarketInfo(Symbol(), MODE_MINLOT);
   double DoshDollop = AccountInfoDouble(ACCOUNT_BALANCE); 
   
   if (UseEquity)
      DoshDollop = AccountInfoDouble(ACCOUNT_EQUITY); 

   
   //Initial lot size
   Lot = NormalizeDouble((DoshDollop / SizeOfDollop) * LotsPerDollopOfCash, decimal);
     
   //Min/max size check
   if (Lot > maxlot)
      Lot = maxlot;
      
   if (Lot < minlot)
      Lot = minlot;      


}//void CalculateLotAsAmountPerCashDollops()
Then add this call to void AutoTrading()

Code: Select all

//Lot size based on account size
   if (!CloseEnough(LotsPerDollopOfCash, 0))
      CalculateLotAsAmountPerCashDollops();
I created the shells from HGB'nCP and forgot to remove the code that deletes untilled pendings at the open of a new candle in void AutoTrading(), from the grid version. Find and remove that or you will be wondering why this is happening if your EA depends on pending trades.

All this is fixed in the shells in the zipfile in post 1.

:xm:
All times are UTC Page 20 of 23