you are not shifting the indicator, you are calculating the indicator from the previous bar. i assume you are drawing the arrow at the position of the ma of the last bar.
//z
that still wouldnt explain the arrow position im getting, for instance these are the values of the line created by:
Buf_5[i]=iMA(NULL,0,3,0,MODE_LWMA,PRICE_LOW,i+1);
with the resulting values of the arrow created by coding to place arrow at bid price if bid price is below Buf_5[0]
Previous bar MA (Buf_5) =1.3489
Current bar MA (Buf_5) =1.3488 curent position of arrow= 1.3493
so even if it was taking the value of the line from the previous bar the arrow still would not have been created below it
can you show your code?
i am only interested in the lines where you fill your Buf_5 and where you fill the arrow_buffer..
//z
ok heres the code for filling the two MA buffers and a function call
double hma=Buf_4[0], lma=Buf_5[0]; Buf_4[i]=iMA(NULL,0,3,0,MODE_LWMA,PRICE_HIGH,i+1); Buf_5[i]=iMA(NULL,0,3,0,MODE_LWMA,PRICE_LOW,i+1); if(grf!=0 && dir()==2 && Bid<lma) {grop=Ask; //open price tc++; grc=tc; grf=0; //direction flag make_arrow(grc,grf,"mixed buy",grop); }
and my arrow function
void make_arrow(int id,bool dir,string type,double price) { ObjectCreate(S1[2,1]+id+"a"+type,OBJ_ARROW,0,Time[0],price,0); if(dir==0) {ObjectSet(S1[2,1]+id+"a"+type,OBJPROP_ARROWCODE,172); } if(dir==1) {ObjectSet(S1[2,1]+id+"a"+type,OBJPROP_ARROWCODE,172); } return; }
EDIT: I should have mentioned, the arrow should be created at the ask price which I realise could be above the line if the bid price was slightly below it, but my broker has a fixed spread of 2 pips the most the arrow should get above the line is 2 pips, but it is being created several pips higher than that 2 pip spread
void make_arrow(int id,bool dir,string type,double price) if(grf!=0 && dir()==2 && Bid<lma) {grop=Ask; //Depending on previous conditions Ask is not necessarry the Openprice, it's the actual price when this part of the code gets triggerd. and for shure //it could never be the same value as one of the "buf" values... tc++; grc=tc; //useless. you can simply pass tc as first parameter.. grf=0; //Second argument of the make_arrow function is type bool, so for better readability use true/false.. make_arrow(grc,grf,"mixed buy",grop); }
at last i suggest to use better variable names, or maybe they have some meaning for you, but make shure that you can read the code still after a few weeks..
//add: also note that when using ask the indicator only work in forward mode. you cannot draw the history when you use Ask..
//add2:
at next if your indicator should work only in forward mode. why you fill your buffers with the variable i. you can simply use:
Buf_4[0]=iMA(NULL,0,3,0,MODE_LWMA,PRICE_HIGH,1); Buf_5[0]=iMA(NULL,0,3,0,MODE_LWMA,PRICE_LOW,1);
//z
Sorry I didnt make my comments very clear. open price in my comment means the price at which to open an order, not the actual open price of a price bar. So that is the price at which I want the arrow to appear, I expected it to appear on the chart 2 pips above the actual Bid price, IF the Bid price is below the MA line but it is not working out that way for some reason it is appearing much higher
yes i know my variables look meaningless but they have a meaning to me lol
tc is trade counter (counts all trade signals including this one)
grc is a separate counter in other programs which use the same functions,
So yes you are right grc is useless as a separate variable and is the same as tc for this test program which only uses 1 set of indications signals, in other programs I wrote there are several signals and grc is a counter for green/red crosses only, in those programs it is different from the over all trade count (tc), but as i am using some of the same functions universally in my programs i keep the same variable names so I dont need to change the function input parameters
grf is green/red flag (for buy or sell conditions).
ah i understand..
do you use this code in a indicator or an EA?
the only thing what could be wrong in this code is the filling of the buf's
Why do you need the buf's . maybe a simple:
double hma=iMA(NULL,0,3,0,MODE_LWMA,PRICE_HIGH,1); double lma=iMA(NULL,0,3,0,MODE_LWMA,PRICE_LOW,1); if(grf!=0 && dir()==2 && Bid<lma) {grop=Ask; //open price tc++; grf=0; //direction flag make_arrow(grc,tc++,"mixed buy",grop); }
does that job..
if no, i don't know...
Im using this code in an indicator to be paired with a trading EA that uses those signals the indicator is mainly for screen display purposes so I'm using those buffers to display the MA lines the EA will use. The indicator displays buy and sell signals and prices and calculates profits/losses based on those signals
ok, i on your case would try to use the same code in the indicator as in the EA, trough that you should get the same signals. if you already did that and the arrows drawn by the indicator and the actual trades differs more than the Spread i don't know the reason.
i'm sorry...
ok thanks for your input I'll figure it out somehow, I didnt do that yet but I will, if I find the cause of the error i'll post it here
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
if an indicator has these lines
Should the value Buf_4[0] be the current value of the line ?
or would i have to use Buf_4[1] to get the current value ?
The reason i ask is i have been getting some strange results when using the buffer[0] value to place arrows on the chart.
for instance when I code the indicator to place an arrow if the bid is lower than Buf_5[0] it is placeing an arrow several pips higher than that, more a kin to a value if I had coded it to place an arrow if bid is higher than Buf_4[0], I have checked and rechecked my code I cant see any logical reason why this should happen unless I am misinterpreting what happens when you use i+1 to shift an MA in a buffer array.
Anyone got any ideas on this ?