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

Need coding help, please
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4346
Page 1 of 2
Author:  LittleCaro [ Fri Jul 10, 2015 1:17 pm ]
Post subject:  Need coding help, please

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)
Author:  dietcoke [ Fri Jul 10, 2015 1:55 pm ]
Post subject:  Need coding help, please

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.
Author:  SteveHopwood [ Fri Jul 10, 2015 6:24 pm ]
Post subject:  Need coding help, please

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:
Author:  LittleCaro [ Mon Jul 13, 2015 7:30 am ]
Post subject:  Need coding help, please

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 !
Author:  oldfella [ Mon Jul 13, 2015 3:17 pm ]
Post subject:  Coding help, please

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
Author:  milanese [ Mon Jul 13, 2015 3:21 pm ]
Post subject:  Coding help, please

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
Author:  LittleCaro [ Mon Jul 13, 2015 4:15 pm ]
Post subject:  Need coding help, please

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)
Author:  oldfella [ Mon Jul 13, 2015 4:38 pm ]
Post subject:  Coding help, please

Hi,

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

Oldfella
Author:  milanese [ Mon Jul 13, 2015 4:43 pm ]
Post subject:  Coding help, please

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
Author:  oldfella [ Tue Jul 14, 2015 9:25 am ]
Post subject:  Need coding help, please

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
All times are UTC Page 1 of 2