How to code? - page 115

 
matrixebiz:
Am I not doing the same thing by doing this?;

if (Hour() 17) TradeHour = false;

Meaning, if hour is between 12 and 17 TradeHour=true , correct?

(Adding && TradeHour in my Buy/Sell statement)

Negating the following statement:

if(Hour()>=12 && Hour()<17)

TradingEnabled=true;

[/CODE]

is

[CODE]

if(Hour()=17)

TradingEnabled=false;

 

One more thing how do I add a re-entry delay to the code so that if a trade was just opened and closed, to wait like 60 min, then check again if trade conditions are met still.

Thank you

 
matrixebiz:
One more thing how do I add a re-entry delay to the code so that if a trade was just opened and closed, to wait like 60 min, then check again if trade conditions are met still. Thank you

It's not clear what is your request.

Do you want to wait for 60 minutes between a trade condition check and the next one ?

If this is your request, may be this should work:

// Global variable

bool TradingEnabled = true; // flag to enable/disabled trading logic

bool TradingCheckDone = false; // flag to know if a a check was just done

datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....

if( !TradingCheckDone )

{

// Default: We assume that trading logic must run ...

TradingEnabled = true;

// ... but only between 12:00:00 and 16:59:59

if(Hour()=17)

TradingEnabled=false;

// We must remember a check was just done

TradingCheckDone = true;

// We must even know when it was done

LastCheckTime = TimeCurrent();

} else

{

// if a hour has passed since the last check, it's time to retry

if( TimeCurrent() - LastCheckTime >= 3600 )

{

TradingCheckDone = false;

}

}

 
gorgoroth:
It's not clear what is your request.

Do you want to wait for 60 minutes between a trade condition check and the next one ?

If this is your request, may be this should work:

// Global variable

bool TradingEnabled = true; // flag to enable/disabled trading logic

bool TradingCheckDone = false; // flag to know if a a check was just done

datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....

if( !TradingCheckDone )

{

// Default: We assume that trading logic must run ...

TradingEnabled = true;

// ... but only between 12:00:00 and 16:59:59

if(Hour()=17)

TradingEnabled=false;

// We must remember a check was just done

TradingCheckDone = true;

// We must even know when it was done

LastCheckTime = TimeCurrent();

} else

{

// if a hour has passed since the last check, it's time to retry

if( TimeCurrent() - LastCheckTime >= 3600 )

{

TradingCheckDone = false;

}

}

No, only if a Trade just happened and closed then I want the EA to wait an hour then check if trade conditions are still met, if they are, then ok, trade again but if not so be it. This code will do what I want then? Will this work in the tester due to the TimeCurrent check?

EDIT: not every hour do the check just after a trade is closed then wait an hour for a condition check and that is it. Then if in a day another Trade is generated and closed then wait again an hour and if no signal then that's it no more waiting checks until the next trade open and close.

Thank you

Attached is a little EA if you could modify it with the right settings that I mentioned. Thanks

Files:
ozfx_method.mq4  11 kb
 

Buy_Limit and Buy_Stop

What is the difference between a Limit order and a Stop order?

Thanks

 
gorgoroth:
Hi everyone,

I've developed a set of functions to manage configuration settings from an EA.

Those functions are exported by a c++ DLL and each of the exported function has the __stdcall calling convetion requested my MQL4.

My problem arises when a function need to return a string to the EA.

Naturally the function cannot:

- return a pointer to a local variabile (variable goes out of scope)

- return a pointer to a dll global variable (problems with concurrent access)

- return a pointer to a heap allocated string (need functions to free memory to be called from the EA: I don't not like this approach)

So i resolved to pass a string and string size from the EA. Es:

string buffer;

GetString( buffer, 30 );

[/CODE]

and from the c++ dll, something like this

void __stdcall GetString( LPTSTR buffer, int BufSize )

{

// Read a string from a some source

....

// -1 to take into account the terminating null character

StringCchCopy( buffer, BufSize-1, ReadStringFromASource );

}

[/CODE]

Here starts the weird behaviour of MQL managing strings returned from a DLL.

using the following code:

string buffer;

GetString( buffer, 30 );

the first time buffer contains the right string. A first question arises: buffer is not initialized but after calling GetString it contains the string returned. I have to suppose that MQL allocates space for a string variable when it's declared.

Next time GetString() is called the string returned seems to be truncated to the length-1 of the previous string length and not resetted as expected because of the 'string buffer;' statement.

Tried even:

[CODE]

string buffer = " "; // 'allocate' 30 blank characters

GetString( buffer, StringLen(buffer) );

but after the first time, when the execution returns to this code, the assignment of buffer does not work any more and buffer still contains the previous read string, and it seems it can only contains the number of characters of his content.

At first I have thought that the null character is not handled very well by MQL and modified the c++ code like this ...

[CODE]

CopyMemory( buffer, ReadStringFromASource, min(BufferSize,ReadStringFromASourceLength) );

and not adding the terminating null character.

But when called from MQL, no string at all is returning.

Has someone an answer ?

No one has problems returning string from DLLs ?

 

I need help..

Can anyone show me a code? to attach to my EA..

One order per signal.. cause sometimes i have 3 signal cause of different TF.. i want all signal to open..

or a code that would take one order per bar but each Timeframe attach to one EA.. don't want to open alot of chart..

 

What is wrong with my BuyStop?

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);

 
matrixebiz:
What is wrong with my BuyStop?

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);

your Stop lose and Take profit..

you should also add *point to your distance before adding it..

OR

Bid-((Distance-StopLoss)*Point),Ask+((Distance+TakeProfit)*Point)

 
Reason: