Questions: to start with MetaTrader and forex - page 85

 
12BPRO:
Dear Codes Guru,

Could someone clarify a few things .........

1) I have a feeling that everytime I CALL an iCustom (e.g in EA), it will recalculate to get the value....

is this assumption Right ???? (like running the whole indicator again)..

2) if the above is true.....What if I set a GlobalVariable in the indicator and let the EA get the GV value..

would it still have to calculate like CALL iCustom....

3) if the above is true.... could you please give some sample on how to make and retrieve GV in the indicator and EA....

I am trying a way to reduce the memory handler overload... and hope this would help.....

Your advice and expertise is highly appreciated....

your truly

AZRUL...

AZRUL

1. If you are calling the indicator with wrong parameters it will do that. Check your parameters

If the above is solved, point 2 and 3 are not necessary

 
mladen:
AZRUL

1. If you are calling the indicator with wrong parameters it will do that. Check your parameters

If the above is solved, point 2 and 3 are not necessary

Dear SIR MLADEN,

1) when I CALL iCustom I don't used parameters.... just this....

e.g.. double GBP_M5 = iCustom(NULL,0,"#ConsoleTrendX05",0,0);

That means my assumption is wrong.... it won't recalculate.....

But a sample of how to do point 2 & 3 (GlobalVariable) would be great SIR....

yours truly

AZRUL...

 
12BPRO:
Dear SIR MLADEN,

1) when I CALL iCustom I don't used parameters.... just this....

e.g.. double GBP_M5 = iCustom(NULL,0,"#ConsoleTrendX05",0,0);

That means my assumption is wrong.... it won't recalculate.....

But a sample of how to do point 2 & 3 (GlobalVariable) would be great SIR....

yours truly

AZRUL...

AZRUL

If you use global variable, you still would have to call the indicator using iCustom() (otherwise there would be no global variable update - so, all in all, almost nothing is changed compared to regular iCustom() call)

 
mladen:
AZRUL If you use global variable, you still would have to call the indicator using iCustom() (otherwise there would be no global variable update - so, all in all, almost nothing is changed compared to regular iCustom() call)

Dear SIR MLADEN,

I was thinking of something like this example.......PLEASE IGNORE THE ORDERSEND()....

Assume you have 2 EAs running in your client terminal and both of them want to Send Order (OrderSend() function), if they called the OrderSend() at the same time MetaTrader will raise an error, to solve this situation , you may write in your EAs a code like that:

while (GlobalVariableCheck("InTrade")) {

Sleep(1000);

}

GlobalVariableSet("InTrade", 1); // set lock indicator

res= OrderSend(....);

GlobalVariableDel("InTrade"); // clear lock indicator

Here the OrderSend() function will work only if the GlobalVariable InTradehas been set.

Note: You have to write this code in the both of the 2 EAs which are trading at the same time.

This is something called semaphoreand it's an example of using GlobalVariables.

yours truly

AZRUL

 
12BPRO:
Dear SIR MLADEN,

I was thinking of something like this example.......PLEASE IGNORE THE ORDERSEND()....

Assume you have 2 EAs running in your client terminal and both of them want to Send Order (OrderSend() function), if they called the OrderSend() at the same time MetaTrader will raise an error, to solve this situation , you may write in your EAs a code like that:

while (GlobalVariableCheck("InTrade")) {

Sleep(1000);

}

GlobalVariableSet("InTrade", 1); // set lock indicator

res= OrderSend(....);

GlobalVariableDel("InTrade"); // clear lock indicator

Here the OrderSend() function will work only if the GlobalVariable InTradehas been set.

Note: You have to write this code in the both of the 2 EAs which are trading at the same time.

This is something called semaphoreand it's an example of using GlobalVariables.

yours truly

AZRUL

AZRUL

I have been working with semaphores since long time ago

1. Metatrader will not raise an error - it executes order send sequentially (one after the other) not in a parallel mode - the error can come from a broker, not metatrader

2. In such a usage of semaphore (when semaphore value is set separately from two different codes) you can fall into a a deadlock

Use the simplest possible ways of order handling. That will provide order handling speed and, hopefully, correct execution. Do not count on local environment - the only thing that matters is your broker and always keep in mind that your broker executes your order, not your code. If it is necessary to wait for a next tick, wait, but forciang a pause will almost sure skip ticks in a time of big volatility

 
mladen:
AZRUL

I have been working with semaphores since long time ago

1. Metatrader will not raise an error - it executes order send sequentially (one after the other) not in a parallel mode - the error can come from a broker, not metatrader

2. In such a usage of semaphore (when semaphore value is set separately from two different codes) you can fall into a a deadlock

Use the simplest possible ways of order handling. That will provide order handling speed and, hopefully, correct execution. Do not count on local environment - the only thing that matters is your broker and always keep in mind that your broker executes your order, not your code. If it is necessary to wait for a next tick, wait, but forciang a pause will almost sure skip ticks in a time of big volatility

Dear SIR MLADEN,

From the above example.... I don't have to use iCustom to get the value.... is this correct....????

I am not planning to used it to send an order.... it was just an example of what I found.....

I am trying to used it to reconised a direction of a particular trade.....

yours truly

AZRUL...

 
12BPRO:
Dear SIR MLADEN,

From the above example.... I don't have to use iCustom to get the value.... is this correct....????

I am not planning to used it to send an order.... it was just an example of what I found.....

I am trying to used it to reconised a direction of a particular trade.....

yours truly

AZRUL...

Yes, you are correct. You do not need iCustom() calls for handling global variables

 
mladen:
Yes, you are correct. You do not need iCustom() calls for handling global variables

Dear SIR MLADEN,

Finally something that I can try and work with..... Do you have an exampleon how to use the GV in the indicator and how to retrieve the GV from EA.... may be your old files....

this would speed up my coding, never done it before....

yours truly

AZRUL...

 
12BPRO:
Dear SIR MLADEN,

Finally something that I can try and work with..... Do you have an exampleon how to use the GV in the indicator and how to retrieve the GV from EA.... may be your old files....

this would speed up my coding, never done it before....

yours truly

AZRUL...

AZRUL

If you use global variable from the indicator and you want to access it from the EA, your indicator : either has to be running while the EA is running too or you have to call your indicator using iCustom()

For global variables simply use 3 functions :
GlobalVariableSet()

GlobalVariableGet()

GlobalVariableDel() (if you do not need the variable any more)

 
mladen:
AZRUL

If you use global variable from the indicator and you want to access it from the EA, your indicator : either has to be running while the EA is running too or you have to call your indicator using iCustom()

For global variables simply use 3 functions :
GlobalVariableSet()

GlobalVariableGet()

GlobalVariableDel() (if you do not need the variable any more)

Dear SIR MLADEN,

Thank for the TIP... I guess have to dig a little dipper on the NET and try on my own first....

yours truly

AZRUL...

Reason: