anyone can help me with the logic? - page 2

 
lucif:

Hi ebal,

the one i'm still have been figuring out is about the global variable...but i still don't know how to declare global variable in meta editor..this is quite an obstacle..

anyway, your advice about read and write it from a file on drive, that's quite opening my eyes...thanks a lot..trying to figure out the code first....



i got how to declare global variable...thanks a lot...trying to implement first...
 
it depend on where in the program you declare the variable : beyond or in a function. by using the keyword extern at the beginning of the line, you declare an extern variable. Take a look here https://book.mql4.com/variables/types There is also an API (a group of functions)to manage Global Variable. https://book.mql4.com/variables/globals
 
Please don't confuse Global Variables and globally declared ( global scope ) variables . . they are two very different things . .
 
there is no diference, beside the scope obviously. The API allow you to declare global variable at the metatrader program level. As you are not allow to write in this area of memory so you have to use the API. A "globaly declared" is the same thing at the EA level, you don't need the API since you are allow to write this area of memory.
 
ebal:
there is no diference, beside the scope obviously. The API allow you to declare global variable at the metatrader program level. As you are not allow to write in this area of memory so you have to use the API. A "globaly declared" is the same thing at the EA level, you don't need the API since you are allow to write this area of memory.

You may have misunderstood the purpose of it all. Do you really need memory calls? Or perhaps variables, at most array suffice? Unless you are dealing with multiple EA's side by side, all of them MUST chat and dance with one another, or something beyond that, chances are, you will be confusing the unnecessary.

i'm trying to build an EA, but i still can't get the logic how to implement it..

the condition is like this.

if MA line 1 and MA line 2 cross, it would open a position -> this one i guess i can. <---- NO GB needed in this case.

when it reach the specific price i've decided, it will close all opened position -> this one i guess also i can <---- NO GB needed in this case.

when the last opened position closed, it will wait until the MA line 1 and MA line 2 cross again, then it will opened another position -> this one i guess also can <---- NO GB needed in this case.

but if the last opened position closed at candle 0 AND THEN MA line 1 and MA line 2 cross again at the same candle (candle 0), it will wait to the next candle to check the condition again -> this one is the problem

is there any code that can get the last closed position detail? Have you consider using iBarShift ?, or OrderCloseTime()?, or MathAbs(MA1,MA2)<n*Point,?? Any other ideas? beside GB, files, etc.


 
You may have misunderstood the purpose of it all. i'm not so sur, lucif was asking for a mean to store permanent data. ten years of consulting guy.
 
ebal:
You may have misunderstood the purpose of it all. i'm not so sur, lucif was asking for a mean to store permanent data. ten years of consulting guy.
and lucif is the one who should be helped. But now, seems like you need more help than him.
 
So lucif, we don't hear about you anymore, was my tips helpful ? ;-)
 
is there any code that can get the last closed position detail? it don't seems to be an easy task. You have the OrderSelect() method. Orders are stored in a table. index 0 is your balance index 1 is your last order and so on But orders are sort by opening date, not by closing date(if it is closed in the same order as it is open, then you are done with it). So may be you'll determine the latest closed order by reading the entries one by one ^^. Another way to deal with order would be to use a ticket_id. But i have a bad news for you guy, if you want to keep track of any value from one execution of an EA to another, you will have to use ... Global variables .... if not file ... or worst a database .... high availability with a disaster recovery plan ... haha .... satanas But regarding the global design of your application, from my point of view you have two way to implement : - The dumb way : at each tick you call dozens of functions to know : If there is opened order, the delta between you moving average and so on and so on (diostar way I guess ;-) - A more efficiant way : Finite-state machine each tick you update the state variable of your machine accordingly and on the next tick, you just have to switch on the value of the variable (instead of several function call which is time consuming) Once again, the only way you have to pass the value of the state variable is by a global variable because of the way EA works. It's just a function executed at each tick. let me know, and i'll send you my bank account number for a little transfer from you ;-) i'm freelance
 
ebal:
is there any code that can get the last closed position detail? it don't seems to be an easy task. You have the OrderSelect() method. Orders are stored in a table. index 0 is your balance index 1 is your last order and so on But orders are sort by opening date, not by closing date(if it is closed in the same order as it is open, then you are done with it). So may be you'll determine the latest closed order by reading the entries one by one ^^. Another way to deal with order would be to use a ticket_id. But i have a bad news for you guy, if you want to keep track of any value from one execution of an EA to another, you will have to use ... Global variables .... if not file ... or worst a database .... high availability with a disaster recovery plan ... haha .... satanas But regarding the global design of your application, from my point of view you have two way to implement : - The dumb way : at each tick you call dozens of functions to know : If there is opened order, the delta between you moving average and so on and so on (diostar way I guess ;-) - A more efficiant way : Finite-state machine each tick you update the state variable of your machine accordingly and on the next tick, you just have to switch on the value of the variable (instead of several function call which is time consuming) Once again, the only way you have to pass the value of the state variable is by a global variable because of the way EA works. It's just a function executed at each tick. let me know, and i'll send you my bank account number for a little transfer from you ;-) i'm freelance


You have some good points but you're making this more complicated than I would care. "is there any code that can get the last closed position detail"? Yes, tons of ways, the correct way for you would depend on your skills and paranoia.

OrderHistoryTotal-1

OrderCloseTime>Last_OrderCloseTime

Order#>Last_Order#

Save Last_Ticket As, Static Variable....GlobalVariableSet....To_File....Over_The_Internet....On_The_Broker's_Server

All of the above methods have their advantages and dis-advantages.

A more efficiant way : Finite-state machine each tick you update the state variable of your machine accordingly and on the next tick, you just have to switch on the value of the variable (instead of several function call which is time consuming)

Tho I've opted to use GlobalVariableSet to save allot of my EA State. This cannot be used for someone who wants to save values of arrays. Your efficient method is nice for Back-Testing but not Bullet-Proof for Live Trading.

Once again, the only way you have to pass the value of the state variable is by a global variable because of the way EA works.

Not true. You can pass values by file also. Anyways take it easy Mr, Consultant for 10 Years.

Reason: