Grid.c

Posted By: forexcoder

Grid.c - 03/28/15 05:58

Good morning everyone. I have some questions to ask about the code in the file Grid.c (in the folder 'Strategy'). First, if you go to take the test, there is an error in 'set (HEDGING);'. I think that the solution is 'Hedge = 2'. Then when it goes to do the loop: 'for (Price = 0; Price <Close + 5 * Grid; Price + = Grid)', at the beginning Price = 0 and then run: 'if (Price <Close and! FindTrade (Price, Grid, true))
enterShort (1, Price, 20 * Grid, Grid); '. Then 'Price = 200Pip' and then performs the same if. Then 'Price=400Pip' and performs the same if and so on until the end of the for statement. So do not ever place the pending orders over the 'Close', that is never run the statement 'else if(Price > Close...'. Is it correct? Thank You.
Posted By: jcl

Re: Grid.c - 03/30/15 17:15

Yes, 'Hedge = 2' is correct - this will be fixed.

Pending orders are placed higher than the Close, though, because the for loop runs until the price is 5 grid lines above the close.
Posted By: forexcoder

Re: Grid.c - 03/30/15 21:23

Thanks Jcl for your reply!!! And excuse me for my English. But I don't understood how the program place the pending orders higher than the Close. The cycle is this:
Code:
for(Price = 0; Price < Close+5*Grid; Price += Grid)


Suppose we are using EURUSD, with last price 1,32, so Close=1,32.
So at the biginning of the cycle,
Price=0
Then, after the first cycle:
Price=Price+Grid=0+200PIP=0+200*0,0001=0+0,02=0,02
Then, the next cycle:
Price=0,02+0,02=0,04
As you can see there will be a lot of cycles before arriving to 1,32+5*200
Instead I think that the solution could be this:
Code:
for(Price = Close; Price < Close+5*Grid; Price += Grid)


And than it it would take another cycle to place the pending orders lower the Close:
Code:
for(Price = Close; Price < Close-5*Grid; Price -= Grid)


I hope I explained.
Thanks again.
Posted By: jcl

Re: Grid.c - 04/07/15 08:33

No, the loop should begin with 0 and not with Close. If it began with Close, the grid lines would be at a different place whenever you restart the system. Beginning with a constant, such as 0, makes sure that you get the same grid lines regardless of the current price.
Posted By: forexcoder

Re: Grid.c - 04/07/15 09:23

I'm sorry but I do not understand what you say. If the price starts from zero than you would have the following:
suppose we are using EURUSD, with last price 1,32, so Close=1,32.
So at the biginning of the cycle, Price = 0 euro:
Price=0
Then, after the first cycle:
Price=Price+Grid=0+200PIP=0+200*0,0001=0+0,02=0,02
Then, the next cycle:
Price=0,02+0,02=0,04
As you can see there will be a lot of cycles before arriving to 1,32+5*200
Where I am wrong?
Posted By: swingtraderkk

Re: Grid.c - 04/07/15 13:41

you are not wrong, but the next line simply moves quickly on if price is below Close - 5*Grid



Code:
// find the lowest grid line
if(Price < Close-5*Grid) continue;

Posted By: forexcoder

Re: Grid.c - 04/08/15 11:40

Ok now it's clear. Thanks very much swingtraderkk. I have only a last question. Why is it necessary use the instruction '(TradeIsShort == IsShort)' in the:
'if((TradeIsShort == IsShort) and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2))' ?
I think it is sufficient write only:
'if between(TradeEntryLimit,Price-Grid/2,Price+Grid/2)'
because it isn't necessary to know if a trade is short or long.
Is it correct?
Thanks a lot.
Posted By: jcl

Re: Grid.c - 04/08/15 14:01

(TradeIsShort == IsShort) checks only long resp. short trades. This allows you to have a long and a short trade pending on any grid line. Otherwise you had only either a long or a short trade, whichever was placed first.
Posted By: forexcoder

Re: Grid.c - 04/08/15 21:11

Now is all clear! Thanks a lot.
© 2024 lite-C Forums