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

Indicator Request
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4019
Page 6 of 7
Author:  milanese [ Sat Jan 17, 2015 6:21 pm ]
Post subject:  Indicator Request

Angat » Sat Jan 17, 2015 6:11 pm wrote:
Thanks Tommaso. I'm just trying to figure out why a global variable isn't being recognised, but if I were to move the same variable instead a function it works.
For sure it would be easier to help you if you cooul post your code or the code snippet, for better understanding, what exactly causes your problem..

Cheers :)

Tommaso
Author:  Reaper [ Sat Jan 17, 2015 10:53 pm ]
Post subject:  Indicator Request

Firstly, thank you both for posting.

I still have no idea why the global variables are acting like that. Anyway I'm going to go back to my EA and carry on developing it.

I will play around with Steve's shell some more when I can. It seems I can learn a lot just from pulling it apart and reading his comments.
Author:  Reaper [ Sat Jan 17, 2015 11:09 pm ]
Post subject:  Indicator Request

I do have one more request for assistance for now if I may.

My EA uses STOP orders to place a order 5 pips below the low of a specific bar. 5 is the minimum distance apparently, will confirm that later. I'm using Heiken Ashi bars, which we know are somewhat lagging over regular candles. So I have the following conditions:

1. if PRICE > LOW[1], Place SELLSTOP at 5 pips below the low.

2. if PRICE < (LOW[1] MINUS 5pips), SELL AT MARKET.

What I need now is some sort of function to check if price is between LOW and LOW-5 for the current bar and then wait for price to move either back above the LOW then place the sellstop or fall below the LOW MINUS 5pips and SELL AT MARKET. And I guess if it stays in that 5 pip range till the next bar, then it does nothing.

Anyone can help with this please? :?:
Author:  AnotherBrian [ Sat Jan 17, 2015 11:48 pm ]
Post subject:  Indicator Request

Angat » Sat Jan 17, 2015 1:10 pm wrote:
Yes thanks, this is basically what I'm asking but for some unknown reason, I have global variables that cant be access within functions.

For example I have

Code: Select all

bool LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));
as a global variable.

Then in LookForTradingOpportunities() function I want to say

Code: Select all

If(LineDetectABZERO) 
 SendShort = true;
But apparently this doesn't work. But does work if I move "bool LineDetectABZERO..." to within LookForTradingOpportunities() .
It is not being detected properly because your asking it to find objects only at the start of the EA, when it is place on the chart, this happens only once. start() is run with each tick. Here is what you need to do....

this is the global
bool LineDetectABZERO;//this initialises the variable, you can make it equal to something, usually a default value like 0, or null. Using bid wont even work here because you have not seen a tick yet.

then near the top of start() you write

Code: Select all

LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));//this will be evaluated at every tick
the value of "LineDetectABZERO" it will be seen in your function.

You need to understand how an ea executes to fully get this....
this is how an EA starts off
drag onto chart
goes through all the variables outside of all the functions, the global variables and initialises them
then it runs init()
then it runs start() at the next tick (on saturday you wont get start() to run unless you have a tick generator)
it runs start and when it finds a function it will go there and then come back
when the ea is removed it will run deinit()

Code: Select all

bool LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));
do you understand the functions "void" "bool", "double" etc?
what's the difference between the functions below (took me a while to get this concept when I started)

Code: Select all

bool myfunction(){
some code
}

void myfunction(){
some code
}
Author:  milanese [ Sun Jan 18, 2015 12:12 am ]
Post subject:  Indicator Request

Angat » Sat Jan 17, 2015 6:10 pm wrote:
Yes thanks, this is basically what I'm asking but for some unknown reason, I have global variables that cant be access within functions.

For example I have

Code: Select all

bool LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));
as a global variable.

Then in LookForTradingOpportunities() function I want to say

Code: Select all

If(LineDetectABZERO) 
 SendShort = true;
But apparently this doesn't work. But does work if I move "bool LineDetectABZERO..." to within LookForTradingOpportunities() .
this you should resolve like:

Code: Select all

bool  LineDetectABZERO = false;

//than in LookForTrading opportunities or were you want
 LineDetectABZERO=false;
if  ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0)) {
 LineDetectABZERO = true;

}

Author:  Reaper [ Sun Jan 18, 2015 12:32 am ]
Post subject:  Indicator Request

Hey guys, thank you both for your replies. I will try your suggestions and set my variables to false firstly. then try the if else statements of setting up bool variables. I guess my way is too much of a shortcut. lol

As for bool, int and void functions.

AFAIK at this stage, bool declares the function as Boolean, i.e true or false and therefore the function has to return a true or false as its final answer.

Same thing with int but has to return integer e.g. can be return(0) for success I think.

Void doesn't return anything. - you would use void e.g. for drawing a trendline. This just produces an output, it doesn't need to return anything.

Please correct me if I'm wrong though.

Thanks again for the replies. Anything you post does help me.

Cheers
Author:  milanese [ Sun Jan 18, 2015 12:48 am ]
Post subject:  Indicator Request

Angat » Sun Jan 18, 2015 12:32 am wrote:Hey guys, thank you both for your replies. I will try your suggestions and set my variables to false firstly. then try the if else statements of setting up bool variables. I guess my way is too much of a shortcut. lol

As for bool, int and void functions.

AFAIK at this stage, bool declares the function as Boolean, i.e true or false and therefore the function has to return a true or false as its final answer.

Same thing with int but has to return integer e.g. can be return(0) for success I think.

Void doesn't return anything. - you would use void e.g. for drawing a trendline. This just produces an output, it doesn't need to return anything.

Please correct me if I'm wrong though.

Thanks again for the replies. Anything you post does help me.

Cheers
look there it should be a help to understand better functions and function types ... http://docs.mql4.com/basis/function
Author:  AnotherBrian [ Sun Jan 18, 2015 1:52 am ]
Post subject:  Indicator Request

Angat » Sat Jan 17, 2015 7:32 pm wrote:Hey guys, thank you both for your replies. I will try your suggestions and set my variables to false firstly. then try the if else statements of setting up bool variables. I guess my way is too much of a shortcut. lol

As for bool, int and void functions.

AFAIK at this stage, bool declares the function as Boolean, i.e true or false and therefore the function has to return a true or false as its final answer.

Same thing with int but has to return integer e.g. can be return(0) for success I think.

Void doesn't return anything. - you would use void e.g. for drawing a trendline. This just produces an output, it doesn't need to return anything.

Please correct me if I'm wrong though.

Thanks again for the replies. Anything you post does help me.

Cheers
You got it! When I was learning I didn't have the coding master on this board to ask these questions, jeez there are some smart cookies on this board.
Check out that link milanese provided above.
Author:  Reaper [ Sun Jan 18, 2015 9:51 am ]
Post subject:  Indicator Request

Angat » Sat Jan 17, 2015 11:09 pm wrote:I do have one more request for assistance for now if I may.

My EA uses STOP orders to place a order 5 pips below the low of a specific bar. 5 is the minimum distance apparently, will confirm that later. I'm using Heiken Ashi bars, which we know are somewhat lagging over regular candles. So I have the following conditions:

1. if PRICE > LOW[1], Place SELLSTOP at 5 pips below the low.

2. if PRICE < (LOW[1] MINUS 5pips), SELL AT MARKET.

What I need now is some sort of function to check if price is between LOW and LOW-5 for the current bar and then wait for price to move either back above the LOW then place the sellstop or fall below the LOW MINUS 5pips and SELL AT MARKET. And I guess if it stays in that 5 pip range till the next bar, then it does nothing.

Anyone can help with this please? :?:

Code: Select all

bool CheckPriceInBufferZone() {

bool NoMansLand = false;
if ((Low[1] -5) < Bid < Low[1])
NoMansLand = true;

if(NoMansLand) 
   for (int i=60*Period(); i >=0; i=i-15)
	if(!NoMansLand) return (false);
	
}

if(CheckPriceInBufferZone() = false)

Place pending short or sell at market;
Just threw together some code, hopefully I'm not too far off.
Author:  Reaper [ Sun Jan 18, 2015 12:31 pm ]
Post subject:  Indicator Request

Well this isn't actually what I need, I need something that is going to check the next 6*60*Period() to see if price moves out of this buffer zone. The issue I have right now is the main bulk of my trading code is sitting in a NewBar(TimeFrame) { } segment in my int Start(). Which means that any function that I need to check subsequent bars is going to get reset on every NewBar. It seems the only way I can accomplish what I need is to rewrite my code structure so its not reliant on NewBar().

This is a tough one. :arrrg:
All times are UTC Page 6 of 7