Need coding help, please

User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Need coding help, please

Post by LittleCaro »

Hello all,

I'm in the making of an ea with a sort of stepma with the incredible steve's shell code.

So, i enter when the stepma changes color, but in strong trend, my orders hit the take profits, and immediately a new order open in the same direction, and i don't want that, i only want a new order when stepma changes color.

I show you the code, please can someone help me.

Thanks !

Code: Select all

//Trading decision.
   bool SendLong=false,SendShort=false;

  
    double clnow = iCustom(Symbol(),BuzzerTimeFrame,"Buzzer",Price,Length,AlertON,EmailON,0,clbar);
    double clpre = iCustom(Symbol(),BuzzerTimeFrame,"Buzzer",Price,Length,AlertON,EmailON,0,clbar+1);
   
     

//Long trade

//Specific system filters
//if (some condition) SendLong = true;
if (clnow>clpre) SendLong = true;

//Usual filters
   if(SendLong)
     {
      //User choice of trade direction
      if(!TradeLong) return;
      
      //Bob's 240 H4 ma trend filter
      if (MaPeriod > 0)
         if (MaTrend != up)
            return;

      if(UseZeljko && !BalancedPair(OP_BUY) ) return;

      //Change of market state - explanation at the end of start()
      //if (OldAsk <= some_condition) SendLong = false;   
     }//if (SendLong)

/////////////////////////////////////////////////////////////////////////////////////

   if(!SendLong)
     {
      //Short trade
      //Specific system filters
      //if (some condition) SendShort = true;
      if (clnow<clpre) SendShort = true;

      if(SendShort)
        {
         //Usual filters

         //User choice of trade direction
         if(!TradeShort) return;

         //Other filters

         //Bob's 240 H4 ma trend filter
         if (MaPeriod > 0)
            if (MaTrend != down)
               return;

         if(UseZeljko && !BalancedPair(OP_SELL) ) return;

         //Change of market state - explanation at the end of start()
         //if (OldBid += some_condition) SendShort = false;   
        }//if (SendShort)

     }//if (!SendLong)

////////////////////////////////////////////////////////////////////////////////////////
//DELETE THIS
   
////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////

//Long 
   if(SendLong)
     {

      stype =" Buy ";
      price=Ask;//Change this to whatever the price needs to be

  
      if(!SendAlertNotTrade)
        {

         stop=CalculateStopLoss(OP_BUY,price);

         take=CalculateTakeProfit(OP_BUY,price);

         //Lot size calculated by risk
         if(RiskPercent>0) SendLots=NormalizeDouble(AccountBalance() * RiskPercent/100 / 1000.0, Digits);

         type=OP_BUY;

        }//if (!SendAlertNotTrade)

      SendTrade=true;

     }//if (SendLong)

//Short
   if(SendShort)
     {
      stype =" Sell ";
      price=Bid;//Change this to whatever the price needs to be

      if(!SendAlertNotTrade)
        {

         stop=CalculateStopLoss(OP_SELL,price);

         take=CalculateTakeProfit(OP_SELL,price);

         //Lot size calculated by risk
         if(RiskPercent>0) SendLots=NormalizeDouble(AccountBalance() * RiskPercent/100 / 1000.0, Digits);
                
         type=OP_SELL;
        }//if (!SendAlertNotTrade)

      SendTrade=true;

     }//if (SendShort)
dietcoke
Trader
Posts: 162
Joined: Tue Nov 15, 2011 9:59 pm

Need coding help, please

Post by dietcoke »

This problem will only happen if you take a profit in the same bar you opened it.

In this situation, the colour change code will still be valid.

When you close the trade have another variable which remains true until the start of the next bar at which point you set it back to false.

meantime, in your trading function only enter the trade open code if the variable is false.
Image
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.

Need coding help, please

Post by SteveHopwood »

DC is dead right.

Another approach is to include a function that examines all the trades in your History tab and returns a value that says, "Yes, the trade closed on the current candle" or, "No, the trade did not close during the current candle".

Include a call to this function within bool IsTradingAllowed().

Suppose you code your function\;
bool DidTradeCloseDuringCurrentCandle()

The call returns true if so, or false if not.

Sing out if you have any problems. I love it when someone is trying to code this stuff for themselves and am happy to help unless I have endured an exceptionally bad day.

: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
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Need coding help, please

Post by LittleCaro »

Thank you for your enlightment guys.

I have updated my shell to the latest shell i find here, and my problem is solved. That's super great, thnaks for this amazing master piece.

But now, i have an other problem.

I work on 20 minutes chart, and when i backtest on regular time frames my expert is working, but this morning, on my 20 minutes charts, nothing happen.

Maybe i should put 20 in the timeframe ?

What should i do for the shell working on offline timeframes ?

I already tried every ticks without succes.

Thanks for all !
oldfella
Trader
Posts: 46
Joined: Sun Jan 11, 2015 4:59 pm

Coding help, please

Post by oldfella »

Hi,
I continually use an indicator on my main platform which I have now copied and loaded onto my second computer.
Problem is that it doesent work on the second computer, and if compiled shows an 1 error, 1 warning.
The 1 error reads "return expressions are not allowed on a global scope" and
the warning reads "not all control paths return a value".

I can't work out how to correct these problems, or understand how the indicator works fine on one platform and not on the second.
Can anyone advise as my programming skills are limited.

Oldfella
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Coding help, please

Post by milanese »

oldfella » Mon Jul 13, 2015 3:17 pm wrote:Hi,
I continually use an indicator on my main platform which I have now copied and loaded onto my second computer.
Problem is that it doesent work on the second computer, and if compiled shows an 1 error, 1 warning.
The 1 error reads "return expressions are not allowed on a global scope" and
the warning reads "not all control paths return a value".

I can't work out how to correct these problems, or understand how the indicator works fine on one platform and not on the second.
Can anyone advise as my programming skills are limited.

Oldfella
If you attach your indicator I will take a look into this...

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
User avatar
LittleCaro
Trader
Posts: 63
Joined: Tue May 19, 2015 7:09 am

Need coding help, please

Post by LittleCaro »

Hey guys,

Always looking for offline charts working with shell.

At the end of code i found these :

So i add 10 and 20 minutes, but nothing again !

Please help :)

Code: Select all

string PeriodText(int per)
{

	switch (per)
	{
   	case PERIOD_M1:
   		return("M1");
   	case PERIOD_M5:
   		return("M5");
   	case PERIOD_M10:
   		return("M10");
   	case PERIOD_M15:
   		return("M15");
   	case PERIOD_M20:
   		return("M20");
   	case PERIOD_M30:
   		return("M30");
   	case PERIOD_H1:
   		return("H1");
   	case PERIOD_H4:
   		return("H4");
   	case PERIOD_D1:
   		return("D1");
   	case PERIOD_MN1:
   		return("MN1");
   	default:
   		return("");
	}

}//End string PeriodText(int per)
oldfella
Trader
Posts: 46
Joined: Sun Jan 11, 2015 4:59 pm

Coding help, please

Post by oldfella »

Hi,

Can you tell how I attach my indicator to this site please.

Oldfella
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Coding help, please

Post by milanese »

oldfella » Mon Jul 13, 2015 4:38 pm wrote:Hi,

Can you tell how I attach my indicator to this site please.

Oldfella
Read there how to attach files ---click----> http://www.stevehopwoodforex.com/phpBB3/kb.php?a=2
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
oldfella
Trader
Posts: 46
Joined: Sun Jan 11, 2015 4:59 pm

Need coding help, please

Post by oldfella »

Hi Milanese,

Thanks for the help and info.

I first wrote this indicator for my Metastock stock trading program. As you will see it will plot lines, as many as you want, with colour , style etc, all selectable.
I must admit I wrote the Empty4 version with advice following Coder Guru's lessons. But age now 80 has overtaken me and the brain doesent work as good as it use too.
So I am grateful for any help you can give
I have compared the codes on both computers, they are the same, so I cannot see why one works and the other doesent.
Allonso is just one of the pseudo names I use.

Regards Oldfella
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Coders Hangout”