MQL4 Learning - page 105

 
Emerald King:
Hello Everyone,

Can someone share some code on how to draw an OHLC bar on a sub window?

Thanks

EK

Hi Emeral King, Have you tried looking through the metatrader forum. They have a lot code in their lol

good luck

 

import .dll

Hi guys,

I'm experienced MQL programmer, but only its basis, now I trying to learn how to work with .dll imports. I searched most of internet, but have not found what I want yet. Please, can someone tell me how may look a source code of the .dll (Have VS 10), with its headers export functions, etc, and how to use it in the MT code? (there may be some EXPORT __stdcall, or similar, I dont exactly know)

What I need to have in the .dll? function prototypes and definitions? Can I use in the .dll function definition some of the pre-defined MT functions, as AccountBalance() or OrderSend()?

Can someone post the full .dll code (if possible there need to call predefined MT functions, as working and from which I can understand what I need to do, and part of .mq4 where is the calling of .dll??.

For example, where I can learn much, here is part of my MQL code, how I do a .dll and call it?

if(UseMM == false) tradeLots = FixLots;

else

{

if(UseFixSL == true)

{

tradeLots = CalculateLots(AccountBalance(), RiskPct, PipPriceUSDlot, 3*FixSL); //3*SL because is three position with same SL and different PT

}

else

{

tradeLots = CalculateLots(AccountBalance(), RiskPct, PipPriceUSDlot, 3*((Ask-zzlow+Offset*Point)/Point));

}

}

if(UseFixSL == true)

{

position1 = OrderSend(Symbol(), OP_BUY, tradeLots, Ask, 0, NormalizeDouble(Ask-FixSL*Point, DecimalDigits), NormalizeDouble(Ask+PT1*Point, DecimalDigits), " L1", 11, 0, Lime);

..........//some unimportant code[/CODE]

CalculateLots definition:

[CODE]double CalculateLots(double From_balance, double Risk_Pct, double Pip_price_USD_lot, int StopLoss)

{

double accBal;

double accBalUSD;

double conversionValue;

double riskFraction;

double Trade_Lots;

if( From_balance < AccountBalance()) accBal = From_balance;

else accBal = AccountBalance();

if(AccountCurrency() == "USD") accBalUSD = accBal;

else if(AccountCurrency() == "EUR")

{

conversionValue = iClose("EURUSD", PERIOD_D1, 1);

NormalizeDouble(conversionValue, 5);

accBalUSD = accBal * conversionValue;

}

else if(AccountCurrency() == "GBP")

{

conversionValue = iClose("GBPUSD", PERIOD_D1, 1);

accBalUSD = accBal * conversionValue;

}

else if( AccountCurrency() == "CZK")

{

conversionValue = iClose("USDCZK", PERIOD_D1, 1);

if( GetLastError() == 4106 || conversionValue 30) conversionValue = USDCZKquote;

NormalizeDouble(conversionValue, 5);

NormalizeDouble(conversionValue, 5);

accBalUSD = accBal / conversionValue;

}

riskFraction = Risk_Pct / 100.00;

Trade_Lots = ((accBalUSD * riskFraction) / (StopLoss * Pip_price_USD_lot));

Trade_Lots = NormalizeDouble(Trade_Lots, 2);

Comment( "AccBal: ", accBal, " risk %: ", RiskPct, " USDlot: ", Pip_price_USD_lot, " SL: ", 3*StopLoss, " Lots: ", Trade_Lots, "\n",

"Currency: ", AccountCurrency() );

return(Trade_Lots);

}

Thanks very much

 
horrigan:
Hi guys,

I'm experienced MQL programmer, but only its basis, now I trying to learn how to work with .dll imports. I searched most of internet, but have not found what I want yet. Please, can someone tell me how may look a source code of the .dll (Have VS 10), with its headers export functions, etc, and how to use it in the MT code? (there may be some EXPORT __stdcall, or similar, I dont exactly know)

What I need to have in the .dll? function prototypes and definitions? Can I use in the .dll function definition some of the pre-defined MT functions, as AccountBalance() or OrderSend()?

Can someone post the full .dll code (if possible there need to call predefined MT functions, as working and from which I can understand what I need to do, and part of .mq4 where is the calling of .dll??.

For example, where I can learn much, here is part of my MQL code, how I do a .dll and call it?

if(UseMM == false) tradeLots = FixLots;

else

{

if(UseFixSL == true)

{

tradeLots = CalculateLots(AccountBalance(), RiskPct, PipPriceUSDlot, 3*FixSL); //3*SL because is three position with same SL and different PT

}

else

{

tradeLots = CalculateLots(AccountBalance(), RiskPct, PipPriceUSDlot, 3*((Ask-zzlow+Offset*Point)/Point));

}

}

if(UseFixSL == true)

{

position1 = OrderSend(Symbol(), OP_BUY, tradeLots, Ask, 0, NormalizeDouble(Ask-FixSL*Point, DecimalDigits), NormalizeDouble(Ask+PT1*Point, DecimalDigits), " L1", 11, 0, Lime);

..........//some unimportant code[/CODE]

CalculateLots definition:

[CODE]double CalculateLots(double From_balance, double Risk_Pct, double Pip_price_USD_lot, int StopLoss)

{

double accBal;

double accBalUSD;

double conversionValue;

double riskFraction;

double Trade_Lots;

if( From_balance < AccountBalance()) accBal = From_balance;

else accBal = AccountBalance();

if(AccountCurrency() == "USD") accBalUSD = accBal;

else if(AccountCurrency() == "EUR")

{

conversionValue = iClose("EURUSD", PERIOD_D1, 1);

NormalizeDouble(conversionValue, 5);

accBalUSD = accBal * conversionValue;

}

else if(AccountCurrency() == "GBP")

{

conversionValue = iClose("GBPUSD", PERIOD_D1, 1);

accBalUSD = accBal * conversionValue;

}

else if( AccountCurrency() == "CZK")

{

conversionValue = iClose("USDCZK", PERIOD_D1, 1);

if( GetLastError() == 4106 || conversionValue 30) conversionValue = USDCZKquote;

NormalizeDouble(conversionValue, 5);

NormalizeDouble(conversionValue, 5);

accBalUSD = accBal / conversionValue;

}

riskFraction = Risk_Pct / 100.00;

Trade_Lots = ((accBalUSD * riskFraction) / (StopLoss * Pip_price_USD_lot));

Trade_Lots = NormalizeDouble(Trade_Lots, 2);

Comment( "AccBal: ", accBal, " risk %: ", RiskPct, " USDlot: ", Pip_price_USD_lot, " SL: ", 3*StopLoss, " Lots: ", Trade_Lots, "\n",

"Currency: ", AccountCurrency() );

return(Trade_Lots);

}
Thanks very much

you can send values from MQL to DLL and let the DLL calculate the output. OrderSend and Account Balance are MQL4 functions so directly your c++ code will not understand this unless you prepare another api in c++ code to understand these functions. In other words just send the values and the some value from c++ dll.. imho..

_DLLAPI int _stdcall something() -- this is the header type you need in DLL's

-guyver.

 

To guyver:

Ok, thanks, I understood that I cannot use predefined pure MQL functions, and how to create a .dll function prototype (C++ rules requires it, MQL not).

But, what is _DLLAPI variable type? where is declared? When I try to use it, receive compilation error that _DLLAPI is not defined??

Second question: how I can call .dll functions? By naming them:

#import "mydll.dll"

int myfunct1(int param1, double param2, string param3);

void myfunct2(void);

void myfunct3(int param4);

#import

or can I import whole .dll? If possible, how?

Somewhere I met that need to type something to .def file? What is it, how to use it and what I must write there?

I'm sorry for this stupid basic questions, but I'm trying code a .dll first time, and have no experiences with it.

 
horrigan:
I'm sorry for this stupid basic questions, but I'm trying code a .dll first time, and have no experiences with it.

No problem, however it may take some time for me to write the whole thing here instead it took me 2 minutes to find this article. ( it says mql5 but it is same for mql4 as well )

How to Exchange Data: A DLL for MQL5 in 10 Minutes - MQL5 Articles

 

Thanks a lot, mate.

The article can help me with my missing basics with .dll coding

When I will have some additional question, I'll ask. Thanks again

 

Display my indicator for another timeframe, than my chart is

Hello,

I have an Indicator, which use the Functions High, Low and Close.

Now I want to change it. I want to add the parameter "Timeframe", so that I can put the indicator on the H1 chart and see the indicator for the M30 oder D1 Timeframe.

Is this possible? How can I do it?!

 

I hope someone can help me.

I want a EA that only bye every day at 17.00 and sell next day at 10.00

That is all.

Thanks

 
phil26:
I hope someone can help me.

I want a EA that only bye every day at 17.00 and sell next day at 10.00

That is all.

Thanks

When you say sell the next day you mean close the previous buy? or open a new sell position.

-guyver

 

yes close the previous buy.

Reason: