0 Views
0 Downloads
0 Favorites
P-L
// Ïàðàìåòðû ñîâåòíèêà:
double LOSSmin     = 5;// ìèíèìàëüíûé ïðîöåíò óáûòêà
double LOSSmax     = 50;// ìàêñèìàëüíûé ïðîöåíò óáûòêà
double minPrLs = 0.5;// ìèíèìàëüíûé ïðîôèò-ëîññ
//-------------------------------------------------------------------+
double Price, kProfitLine;
double STL = 0; double PFL = 0; double LOT = 0; double deltareal=1; double LOSS = 0.1;
int init()  {DrowPriceLine(); LineStop(); Price = ObjectGet("Price", 1); return(0);}
int deinit(){Comment (" ");ObjectDelete( "Profit");ObjectDelete ("321");ObjectDelete( "Price");ObjectDelete( "StopLine");return(0); }
int start()
  {
//----
if (IsConnected()) {
     while ( ObjectFind("StopLine")!=(-1) && ObjectFind("Price")!=(-1)&& ObjectFind("Profit")!=(-1) )
     {if (ObjectFind("StopLine") == (-1)) {LineStop();}
    
     if (ObjectFind("321") == (-1)) {ObjectCreate ("321",OBJ_ARROW,0,Time[WindowBarsPerChart( )/2] ,WindowPriceMin()+((WindowPriceMax() - WindowPriceMin())/10) );
     ObjectSet("321", OBJPROP_ARROWCODE, 241); ObjectSet("321", OBJPROP_WIDTH, 2); } 
     
     Price = ObjectGet("Price", 1);// öåíà æåëòîé ëèíèè - öåíà îòêðûòèÿ îòëîæåííîãî îðäåðà
     
     STL = ObjectGet("StopLine", 1);PFL = ObjectGet("Profit", 1); textset(); 
       }
//-----------------------------------
     ObjectCreate( "StopLine", OBJ_HLINE, 0, 0, STL); ObjectSet( "StopLine", 6, Red);
     ObjectSet( "StopLine", 8, 1);WindowRedraw( );
     ObjectCreate( "Profit", OBJ_HLINE, 0, 0, PFL); ObjectSet( "Profit", 6, Blue);
     ObjectSet( "Profit", 8, 1);WindowRedraw( );
     ObjectCreate( "Price", OBJ_HLINE, 0, 0, Price); ObjectSet( "Price", 6, Teal);
     ObjectSet( "Price", 8, 1);WindowRedraw( );
     if (MessageBox ("Îòêðûòü îòëîæåííûé îðäåð ?","Ñêðèïò",1)==1) startset();
    
} else MessageBox ("Íåò ñîåäèíåíèÿ ñ ñåðâåðîì !","Ñêðèïò");   
//----
   return(0);
}
//+------------------------------------------------------------------+

int LineStop() {// Ðèñóåì ëèíèþ (êîòîðàÿ ìèãàåò)
ObjectDelete( "StopLine");ObjectDelete( "Profit");  
ObjectCreate( "StopLine", OBJ_HLINE, 0, 0,WindowPriceMin() + ((WindowPriceMax() - WindowPriceMin())/2.5) );
ObjectSet( "StopLine", 6, Red); ObjectSet( "StopLine", 8, 1);
ObjectCreate( "Profit", OBJ_HLINE, 0, 0,WindowPriceMax() - ((WindowPriceMax() - WindowPriceMin())/2.5) );
ObjectSet( "Profit", 6, Blue); ObjectSet( "Profit", 8, 1); WindowRedraw( ) ;
return(0);  }

//+------------------------------------------------------------------+
double textset() { 
  double delta = WindowPriceMax() - WindowPriceMin();
  double PriceMax = WindowPriceMax() - delta/10;
  double PriceMin = delta/10 + WindowPriceMin();
  if (ObjectGet("321", 1) > PriceMax) ObjectSet("321",1,PriceMax);
  if (ObjectGet("321", 1) < PriceMin) ObjectSet("321",1,PriceMin);
  double deltascreen = PriceMax - PriceMin;
  LOSS = (((ObjectGet("321", 1)-PriceMin)/deltascreen)*(LOSSmax - LOSSmin))+LOSSmin;
    if (STL > (Price  + Point*MarketInfo(Symbol(), MODE_STOPLEVEL))) deltareal = (STL - Price )/Point;
    if (STL < (Price  - Point*MarketInfo(Symbol(), MODE_STOPLEVEL))) deltareal = (Price  - STL)/Point;
  LOT = ((AccountFreeMargin()*(LOSS/100))/MarketInfo(Symbol(), MODE_TICKVALUE))/deltareal;
  LOT = Round(LOT);
  double LOSSreal = (LOT*deltareal*MarketInfo(Symbol(), MODE_TICKVALUE)/AccountFreeMargin())*100;
  kProfitLine = (ObjectGet("Profit", 1)-ObjectGet("Price", 1))/(ObjectGet("Price", 1)-ObjectGet("StopLine", 1));
   WindowRedraw( ) ;
   Comment ( "P/L="+DoubleToStr(kProfitLine,1)+",Ls="+DoubleToStr(AccountFreeMargin()*LOSSreal/100,0)+",L%="+DoubleToStr(LOSSreal,0)+",Lot="+DoubleToStr(LOT,2));
return(0); }

int startset()  { 
//-----
 if (kProfitLine<minPrLs) {MessageBox ("P/L ìåíüøå äîïóñòèìîãî","Ñêðèïò");return(0); }
 
 int resi = 0;
Price = MathRound (Price * MathPow ( 10, MarketInfo(Symbol(), MODE_DIGITS)) );
Price = Price / MathPow ( 10, MarketInfo(Symbol(), MODE_DIGITS)); 
STL = MathRound (STL * MathPow ( 10, MarketInfo(Symbol(), MODE_DIGITS)) );
STL = STL / MathPow ( 10, MarketInfo(Symbol(), MODE_DIGITS));
PFL = MathRound (PFL * MathPow ( 10, MarketInfo(Symbol(), MODE_DIGITS)) );
PFL = PFL / MathPow ( 10, MarketInfo(Symbol(), MODE_DIGITS));
// ïðîäàæà
if ((STL>Price) && (MarketInfo( Symbol(), MODE_ASK) < Price)) resi = OrderSend (Symbol(),OP_SELLLIMIT,LOT, Price , 0, STL, PFL );
if ((STL>Price) && (MarketInfo( Symbol(), MODE_ASK) > Price)) resi = OrderSend (Symbol(),OP_SELLSTOP,LOT, Price , 0, STL, PFL );
// ïîêóïêà
if ((STL<Price) && (MarketInfo( Symbol(), MODE_BID) > Price)) resi = OrderSend (Symbol(),OP_BUYLIMIT,LOT, Price , 0, STL, PFL );
if ((STL<Price) && (MarketInfo( Symbol(), MODE_BID) < Price)) resi = OrderSend (Symbol(),OP_BUYSTOP,LOT, Price , 0, STL, PFL );
return(0);  }

void DrowPriceLine()
{
if (ObjectFind("Price") == (-1)){
ObjectCreate( "Price", OBJ_HLINE, 0, 0,WindowPriceMin() + ((WindowPriceMax() - WindowPriceMin())/2) );
ObjectSet( "Price", 6, Teal); ObjectSet( "Price", 8, 1); WindowRedraw( ) ;}   
}
   
double Round(double A1) // Ôóíêöèÿ îêðóãëÿåò À1 äî Øàãà Ëîòà è ïðîâåðÿåò íèæíþþ ãðàíèöó è âåðõíèå ãðàíèöû
{
A1 = MathRound (A1 / MarketInfo(Symbol(), MODE_LOTSTEP));
A1 = A1 * MarketInfo(Symbol(), MODE_LOTSTEP);

if (A1 < MarketInfo(Symbol(), MODE_MINLOT)) A1 = MarketInfo(Symbol(), MODE_MINLOT);
if (A1 > (AccountFreeMargin()/MarketInfo(Symbol(),MODE_MARGINREQUIRED))) A1 = (AccountFreeMargin()/MarketInfo(Symbol(),MODE_MARGINREQUIRED));  //ñðåäñòâà äëÿ îòêðûòèÿ 1 ëîòà
return(A1);
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---