Spread trading in Meta Trader - page 159

 

Thank you for the information.

Here's what I can't figure out. If I use date obtained with MarketInfo(),

 int exp1 =MarketInfo(Simbol1,MODE_EXPIRATION);
 int exp2 =MarketInfo(Simbol2,MODE_EXPIRATION);

How to set a condition to prohibit opening positions in 3 weeks? And correspondingly, if I understand correctly, it would be reasonable to close the existing positions. This is the date of expiration, and the closer to it, the higher the risk of force majeure.

 
leonid553:

Here is a script that tracks bid-ask spread (specifically for brokerage brokerage).

Somewhere above in the middle of the thread there is the same version, but as an indicator.

My script consumes significant CPU resource (-schedule), so it's better to put it just before opening/closing, and then remove it at once.

6NZ0, M1

How about using goldtrader's example with code from your script

    //Задаем цены аск и бид тикера
    Ask_Tiker = MarketInfo(_tiker,MODE_ASK);
    Bid_Tiker = MarketInfo(_tiker,MODE_BID);
Like a filter in an EA. And you don't need a script.
 
Vitya:

Thank you for the information.

Here's what I can't figure out. If I use date obtained with MarketInfo(),

How to set a condition to prohibit opening positions in 3 weeks? And correspondingly, if I understand correctly, it would be reasonable to close the existing positions. This is the date of expiration, and the closer to it, the higher the risk of force majeure.

it is possible to make an alert conclusion about approaching expiry, and in the Expert Advisor it is necessary to check each trade against the maximum allowable spread
 
Vitya:

And if you use the construction that goldtrader suggested with the code from your script

The same as the filter in the Expert Advisor. And the script is not needed.


Well, that's obvious! The script is only needed for manual trading.

You can also insert the close/open conditions by ticker in your Expert Advisor. However, there is a difficulty there. The work of the EA will have to be looped (and it means - to overload the processor), otherwise this filter will be absolutely useless for low liquidity contracts.

 

Good afternoon, my question is right on point.

The spread indicator in its PROPERTIES allows to set the names of the instruments.

extern string Symbol_1 = "GCG1";
extern string Symbol_2 = "SIF1";

How do I write

double iCustom(

string symbol, int timeframe,

- Which tool should I select - the first or the second one? Or any of them?



 
Rita:


there is no way to apply it here

You need to embed the code in the Expert Advisor and specify the condition there

//----
extern string Simbol1 = "ESZ0"; extern double k1 =1;
extern string Simbol2 = "NQZ0"; extern double k2 =1;
extern double lot =1;
//----
extern double maxSpred =30;
extern int MinTimeExp =1800000;

int exp1,exp2,v1,v2;
//+------------------------------------------------------------------+
double StoimPunkt(string B){return(MarketInfo(B,MODE_TICKVALUE)/(MarketInfo(B,MODE_TICKSIZE)/MarketInfo(B,MODE_POINT)));}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
double sred(int typ,string B)
{double j;RefreshRates();
if(typ==0)j=((MarketInfo(B+"#I",MODE_ASK)-MarketInfo(B,MODE_BID))/MarketInfo(B,MODE_POINT))*StoimPunkt(B);
if(typ==1)j=((MarketInfo(B,MODE_BID)-MarketInfo(B+"#I",MODE_BID))/MarketInfo(B,MODE_POINT))*StoimPunkt(B);
if(j<0)j=0;return(j);}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
int start()
{
exp1 =MarketInfo(Simbol1,MODE_EXPIRATION);
exp2 =MarketInfo(Simbol2,MODE_EXPIRATION);
v1 =MarketInfo(Simbol1,MODE_TRADEALLOWED);
v2 =MarketInfo(Simbol2,MODE_TRADEALLOWED);

if((sred(0,Simbol1)*lot*k1+sred(1,Simbol1)*lot*k1<maxSpred)&&(sred(0,Simbol2)*lot*k2+sred(1,Simbol2)*lot*k2<maxSpred)&&
(TimeCurrent()+MinTimeExp<exp1)&&(TimeCurrent()+MinTimeExp<exp2)&&(v1 ==1)&&(v2 ==1))
{



код советника




}
}
//+------------------------------------------------------------------+

 
I see, thank you.
 
forex-k:

there is no way to apply it here

You need to embed the code in the Expert Advisor and specify the condition there

//----
extern string Simbol1 = "ESZ0"; extern double k1 =1;
extern string Simbol2 = "NQZ0"; extern double k2 =1;
extern double lot =1;
//----
extern double maxSpred =30;
extern int MinTimeExp =1800000;

int exp1,exp2,v1,v2;
//+------------------------------------------------------------------+
double StoimPunkt(string B){return(MarketInfo(B,MODE_TICKVALUE)/(MarketInfo(B,MODE_TICKSIZE)/MarketInfo(B,MODE_POINT)));}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
double sred(int typ,string B)
{double j;RefreshRates();
if(typ==0)j=((MarketInfo(B+"#I",MODE_ASK)-MarketInfo(B,MODE_BID))/MarketInfo(B,MODE_POINT))*StoimPunkt(B);
if(typ==1)j=((MarketInfo(B,MODE_BID)-MarketInfo(B+"#I",MODE_BID))/MarketInfo(B,MODE_POINT))*StoimPunkt(B);
if(j<0)j}0;return(j);}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
int start()
{
exp1 =MarketInfo(Simbol1,MODE_EXPIRATION);
exp2 =MarketInfo(Simbol2,MODE_EXPIRATION);
v1 =MarketInfo(Simbol1,MODE_TRADEALLOWED);
v2 =MarketInfo(Simbol2,MODE_TRADEALLOWED);

if((sred(0,Simbol1)*lot*k1+sred(1,Simbol1)*lot*k1<maxSpred)&&(sred(0,Simbol2)*lot*k2+sred(1,Simbol2)*lot*k2<maxSpred)&&
(TimeCurrent()+MinTimeExp<exp1)&&(TimeCurrent()+MinTimeExp<exp2)&&(v1 ==1)&&(v2 ==1))
{



код советника




}
}
//+------------------------------------------------------------------+



Thank you again. It answers my questions as well.
 

Information for reflection...

MC - YM (4 ^ 9)

 
leonid553:

Information for reflection...

MC - YM (4 ^ 9)


=================================


Reason: