| |
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж
// AG_AT.mq4 Example 15 (instruments 14, 23)
// Custom Automatic Trade function.
// Used at the construction of automatic trade strategy for application AutoGraf 4
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж
// It is not realization of trade strategy. It is a technical example of management ..
// .. instruments for the construction of the own automatic trade system.
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж 0 жж
#property library
#import "AG_Lib.ex4"
int AG_Magic_Number();
// Magic Number calculation
int AG_Message(string& Message[], string _Text);// Text messages record in Message[]
// Control action record in Manager[][]
int AG_Set_Instr(double& Manager[][], int ii, double v1, double v2, double v3,
double v4, double v5, double v6, int io , int ih);
int AG_Delete_Instr(double&Manager[][], int ii, int io,int ih);// Deleting of instruments
#import "AG_Trade_Criterion.ex4"
int AG_Trade_Criterion_1();// First function of trade criterion definition
int AG_Trade_Criterion_2();// Second function of trade criterion definition
#import
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж 1 жж
int AG_AT(int Parol_AT, double Order[][], string Object[], double Instrument[][][][],
int Ddraw_Object[][], double& Tuning[], double& Manager[][], string& Message[])
{
//================================================================================== 2 ==
if (!IsDemo()) // For demo account without limits
{
if(Parol_AT != AccountNumber() + 1) // If incorrect password enter
{ // Example of message (max 62 symbols)
AG_Message(Message, "Developer J.Smith, http://company.com ");
AG_Message(Message, "Incorrect password for AT function.");
return(0);// Exit from AT function
} // AT function will automatic turn off by AutoGraf
}
//================================================================================== 3 ==
static int Count = 0; // Counter
int MN; // MagicNumber it is recommended to calculate in AG_Magic_Number() function
static int Ticket; // Unique identifier of order
string Comm = "AG_AT";// Commentary (it is recommended "AG_AT")
//==================================================================================
double Lot = NormalizeDouble(Tuning[1]],2); // Value of lots
int Per = NormalizeDouble(Tuning[2],0); // Value of percents (integer)
int Slip = NormalizeDouble(Tuning[3],0); // Slippage (in points)
int SL = NormalizeDouble(Tuning[4],0); // StopLoss (in points)
int TP = NormalizeDouble(Tuning[5],0); // TakeProfit (in points)
int Ds = NormalizeDouble(Tuning[6],0); // Distance (in points)
int St = NormalizeDouble(Tuning[7],0);// Modification step (in points)
//================================================================================== 4== if (Count==0) // It can be done one time at the beginning
{// Example of message (max 62 symbols):
AG_Message(Message, "Developer J.Smith, http://company.com ");
Count++; // Amount of visits of this block
Lot = 0.0;// 0.0 means that the lots amount is calculated in AutoGraf
Per = 7; // .. on the basis of value percent (here 7%) of sum of balance
Slip = 1;
SL = 100;
TP = 75;
Ds = 20;
St = 3;
/*
Lot = 2.5; // If lots amount Lot (Tuning[1]) greater than zero, ..
Per = 0; // .. then value of percents (Tuning[2]) in application ..
Per = 12; // .. not taken into account and it will be calculated ..
// .. regardless of variable Per(Tuning[2]) value.
Lot = 0.0; // If lots amount Lot (Tuning[1]) in application ..
Per = 7; // .. AutoGraf is required to calculate on the basis ..
// .. of set percent (Tuning[2]) value, then ..
// .. .. Lot (Tuning[1]) value is required to set in zero.
*/
//================================================================================== 5== Tuning[1] = Lot; // Lots value
Tuning[2] = Per; // Value of percents (integer)
Tuning[3] = Slip; // Slippage (in points)
Tuning[4] = SL; // StopLoss (in points)
Tuning[5] = TP; // TakeProfit (in points)
Tuning[6] = Ds; // Distance (in points)
Tuning[7] = St;// Modification step (in points)
AG_Message(Message,"Changing of options from АТ..");// Example of message (max. 62 chars.)
return(1); // Exit after retuning of parameters
}
// After a control from AG_AT will be returned..
// .. in application AutoGraf, in the AG_ind indicators ..
// ... window is possible to look new values of tunings.
//================================================================================== 6 ==
bool BLim = false; // We consider, that BuyLimit orders are not present
bool SLim = false; // СWe consider, that SellLimit orders are not present
int My_Ord = NormalizeDouble(Order[0][0],0); // Orders amount in our window
for (int i=1; i<=My_Ord; i++) // On the list of orders
{
if (NormalizeDouble(Order[i][6],0) == 2.0)// Order BuyLimit is found
BLim = true;
if (NormalizeDouble(Order[i][6],0) == 3.0)// Order SellLimit is found
SLim = true;
}
bool Plan_BLim = false; // We consider, that the Planned order BuyLimit is not present
bool Plan_SLim = false; // We consider, that the Planned order SellLimit is not present
int Plan_Ord = NormalizeDouble(Instrument[0][1][0][0],0);// Instrument amount in a window
for (int p=1; p<=Plan_Ord; p++) // On the list of order
{
// If the Planned order BuyLimit is already present
if (NormalizeDouble(Instrument[0][1][p][5],0) == 2.0)
Plan_BLim = true; // If the Planned order SellLimit is already present
if (NormalizeDouble(Instrument[0][1][p][5],0) == 3.0)
Plan_SLim = true;
}
//================================================================================== 7 ==
int TT = TimeCurrent(); // Current time
int Tm1 = StrToTime("15:15"); // We want to set the Planned order in a period ..
int Tm2 = StrToTime("16:00"); // .. from 15:15 to 16:00
int Tm = StrToTime("18:30"); // Аbsolute time of execution of instrument 23 Planned_Order
int Tm_Cls = StrToTime("23:59"); // Absolute time of execution of instrument 14 Close_All
//================================================================================== 8 ==
// If in a window a orders is not present, then setting of instruments
// the Planned_Order in a set period
if (TT > Tm1 && TT < Tm2 && NormalizeDouble(Order[0][0],0) == 0.0)
{
// If order BuyLimit not present and Planned_Order BuyLimit still not set
if( BLim == false && Plan_BLim == false )
{
double Price = Ask - 25*Point;// Executione price of instrument
// We set an instrument 23 Planned_Order
AG_Set_Instr(Manager, 23, Tm, Price, 50, 20, 2, Lot*0.5, 0, 0);
// 23 = index of instrument
// Tm = absolute execution time of instrument
// Price = execution price of instrument (order will be open at this price or ..
// .. at nearest possible price if a price will go away)
// 50 = StopLoss of opened order (points)
// 20 = TakeProfit of opened order (points)
// 2 = type of order BuyLimit
// Lot*0.5 = lots amount of opened order
// 0 = a parameter absents
// 0 = a parameter absents
}
//================================================================================= 9 ==
// If order BuyLimit not present and Planned_Order BuyLimit still not set
if( SLim == false && Plan_SLim == false )
{
Price = Bid + 25*Point; // Execution price of instrument
// We set an instrument 23 Planned_Order
AG_Set_Instr(Manager, 23, Tm, Price, 50, 20, 3, Lot*0.5, 0, 0);
}
// If an instrument Close_All still not set
//================================================================================= 10 == if( NormalizeDouble(Instrument[0][2][32][0],0) == 0.0 )
// 0 = push-type index for an instrument 14
// 2 = push-type index for an instrument 14
// 32 = push-type index for an instrument 14
// 0 = flag of set of instrument
// 0.0= instrument not set (1.0 = is set))
// We set an instrument 14 Close_All
AG_Set_Instr(Manager, 14, Tm_Cls, 30, 0, 0, 0, 0, 0, 0);
// 14 = index of instrument
// Tm_Cls = absolute execution time of instrument
// 30 = percent from the height of screen
// 0 = a parameter absents
}
//================================================================================= 11 ==
if (NormalizeDouble(Order[0][0],0)>0.0)
{
for (p=1; p<=Plan_Ord; p++) // On the list of orders
{
// If a Planned_Order BuyLimit is set
if (NormalizeDouble(Instrument[0][1][p][5],0) == 2.0)
{
AG_Delete_Instr(Manager, 23, p, 0);// We delete an instrument 23 Planned_Order
AG_Message(Message, "АТ: We delete Planned_Order BuyLimit.");// Message
}
if (NormalizeDouble(Instrument[0][1][p][5],0) == 3.0)
{
AG_Delete_Instr(Manager, 23, p, 0);// We delete an instrument 23 Planned_Order
AG_Message(Message, "АТ: We delete Planned_Order SellLimit.");// Message
}
}
}
//================================================================================= 12 ==
return(1); // Normal return
// return(0); // Function AT will be closed in application AutoGraf 4
}
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж End of module жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж 13 жж
|
|