My shell EA code

DigitalCrypto
Trader
Posts: 237
Joined: Tue Feb 24, 2015 4:38 am

My shell EA code

Post by DigitalCrypto »

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
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.

My shell EA code

Post by SteveHopwood »

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:
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.
DigitalCrypto
Trader
Posts: 237
Joined: Tue Feb 24, 2015 4:38 am

My shell EA code

Post by DigitalCrypto »

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:
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.

My shell EA code

Post by SteveHopwood »

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:
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.
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.

My shell EA code

Post by SteveHopwood »

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:
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.
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.

My shell EA code

Post by SteveHopwood »

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:
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.
DigitalCrypto
Trader
Posts: 237
Joined: Tue Feb 24, 2015 4:38 am

My shell EA code

Post by DigitalCrypto »

Awesome Steve! Do you plan on keeping the originals up here for a while or will they be removed at some point?
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.

My shell EA code

Post by SteveHopwood »

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:
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.
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.

My shell EA code

Post by SteveHopwood »

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:
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.
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.

My shell EA code

Post by SteveHopwood »

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:
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.
Post Reply

Return to “Coders Hangout”