Useful features from KimIV - page 71

 
You need to number the upper and lower fractals separately. In the function parameters, specify UPPER or LOWER type and fractal number. By the way, if you were to number the top and bottom kinks separately when searching for zigzag inflection points as well, it would be more convenient to use.
 
KimIV писал(а) >>

Yes, there isn't... Because I couldn't decide how to number such fractals:

What if something like this doesn't count as a fractal formation. An option?

 
kombat. I don't agree with this option. The fact is that just when there are two fractals on the same bar, it is a sign of the well-known figure "lens", sometimes called "diamond". Therefore this figure can be fished out in the Expert Advisor by this sign.
 
Question to Docs and Igor = Is it possible to build "Profit" or "Funds" indicator as a continuous line from time (of different Т\F) in a separate window from time ( meaning - control of portfolio performance in dynamics)... Unfortunately, there is an indicator on Igor's website, but it is in the form of a table and static ... (or maybe there is one - give me a link) ....
 
khorosh писал(а) >>
kombat. I don't agree with this option. The fact is that just when there are two fractals on one bar, it is a sign of the well-known figure "lens", sometimes called "diamond". Therefore this figure can be fished out in the EA by this sign.

For definition YES, but for numbering, which is what it's all about...

 
nuj >> :
Question to Docs and Igor = Is it possible to build a "Profit" or "Funds" indicator as a continuous line from time (of different Т\F) in a separate window from time ( meaning - control of portfolio performance in dynamics)... Unfortunately, there is an indicator on Igor's website, but it is in the form of a table and static ... (or maybe there is one - give me a link) ....

search through the forum

Files:
equity_v7.mq4  17 kb
 

and ask if you have an advisor that:

1. picks up all open positions.

2. sets a stop at no loss.

3.trawl

4. closes positions in three levels. for example:

Lot equals 1.

Exit 1 - 50% of the lot is closed, e.g. 30 pips from the opening price.

2 way out - 30% of the lot is closed, for example 70 points of the open price.

3 way out - 20% of the lot is closed, for example on MA crossing.

Thank you.

 

Good afternoon, Could you please tell me how to implement NumberOfBarOpenLastPos function in this simple Expert Advisor,

so that an order is triggered once per bar... I put the function in the code, but nothing works...

//--------------------------------------------------------------------
// tradingexpert.mq4
//
//--------------------------------------------------------------------
#property copyright "Copyright © Book, 2007"
#property link "http://AutoGraf.dp.ua"
//--------------------------------------------------------------- 1 --
// Numerical values for M15
extern double StopLoss =200; // SL for the order being opened
extern double TakeProfit =10; // TP for the order being opened
extern intern Period_MA_1=11; // Period MA 1
extern int Period_MA_2=31; // Period MA 2.
extern double Rastvor =28.0; // Distance between MAs.
extern double Lots =0.1; // Fixed number of lots.
extern double Prots =0.07; // Percentage of free funds

bool Work=true; // Expert Advisor will work.
string Symb; // Name of the financial instrument
//--------------------------------------------------------------- 2 --
int start()
{
int
Total, // Number of orders in the window
Tip=-1, // Order type selected (B=0,S=1)
Ticket; // Order number
double
MA_1_t, // Value. MA_1 current value
MA_2_t, // MA_2_t value. MA_2_t current value, // MA_2_t value.
Lot, //Lots number in Order currently selected
Lts, //Number of lots in an open order
Min_Lot, // Minimum number of lots
Step, // Step of lot size change
Free, // Current free funds
One_Lot, // Value of one lot
Price, // Price of the selected order
SL, // SL price of the selected order
TP; // TP of the selected order
bool
Ans =false, // Server answer after the closing
Cls_B=false, // Criteria for closing Buy
Cls_S=false, // Criterion for closing Sell
Opn_B=false, // Criterion for opening Buy
Opn__S=false; // criterion for opening Sell
//--------------------------------------------------------------- 3 --
//Preprocessing
if(Bars < Period_MA_2) // Not enough bars
{
Alert("Not enough bars in the window. Expert Advisor is not working.");
return; // Exit start()
}
if(Work==false) // Critical error.
{
Alert("Critical error. Expert Advisor is not working.");
return; // Exit from start()
}
//--------------------------------------------------------------- 4 --
// Order counting
Symb=Symbol(); // Name of financial instrument.
Total=0; // Number of orders
for(int i=1; i<=OrdersTotal(); i++) // Order loop
{
if(OrderSelect(i-1,SELECT_BY_POS)==true) // If the following
{ // Order analysis:
if (OrderSymbol()!=Symb)continue; // Not our financial instrument
if (OrderType()>1) // We have a pending order
{
Alert("Pending order detected. Expert Advisor is not working;)
return; // Exit()
}
Total++; // Market order counter
if (Total>1) // No more than one order
{
Alert("Several market orders. Expert Advisor is not working;)
return; // Exit()
}
Ticket=OrderTicket(); // Order number selected.
Tip =OrderType(); // Type of the selected order.
Price =OrderOpenPrice(); // Price of the selected order.
SL =OrderStopLoss(); // SL of the selected order.
TP =OrderTakeProfit(); // TP of the selected order.
Lot =OrderLots(); // Number of lots
}
}
//--------------------------------------------------------------- 5 --
// Trade criteria
MA_1_t=iMA(NULL,0,Period_MA_1,0,MODE_LWMA,PRICE_TYPICAL,0); // MA_1
MA_2_t=iMA(NULL,0,Period_MA_2,0,MODE_LWMA,PRICE_TYPICAL,0); // MA_2

if (MA_1_t > MA_2_t + Rastvor*Point) // if difference between
{ // ...MA1 and 2 is large
Opn_B=true; // Open Buy criterion
Cls_S=true; // Close criterion Sell
}
if (MA_1_t < MA_2_t - Rastvor*Point) // If difference between
{ // ...MA_1 and 2 is large
Opn_S=true; //open Sell criterion
Cls_B=true; //Click criteria Buy
}
//--------------------------------------------------------------- 6 --
// Close orders
while(true) //Order closing loop.
{
if (Tip==0 && Cls_B==true) //Open Buy order.
{ //there is a closing criterion
Alert("Trying to close Buy ",Ticket,";)
RefreshRates(); // Refresh data
Ans=OrderClose(Ticket,Lot,Bid,2); // Close Buy
if (Ans==true) // It worked :)
{
Alert ("Closed Buy order ",Ticket;)
break; // Exit from the close loop
}
if (Fun_Error(GetLastError())==1) // Error handling
continue; // retry
return; // Exit from start()
}

if (Tip==1 && Cls_S==true) // Sell order opened.
{ // there is a close criterion
Alert("Attempting to close Sell ",Ticket,";)
RefreshRates(); // Refresh data
Ans=OrderClose(Ticket,Lot,Ask,2); // Closing Sell
if (Ans==true) // It worked :)
{
Alert ("Sell order closed ",Ticket;)
break; // Exit from the close loop
}
if (Fun_Error(GetLastError())==1) // Error handling
continue; // retry
return; // Exit from start()
}
break; // Exit while
}
//--------------------------------------------------------------- 7 --
// Order values
RefreshRates(); // Refresh data
Min_Lot=MarketInfo(Symb,MODE_MINLOT); // Minimal number of lots
Free =AccountFreeMargin(); // Free funds
One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);// Value of 1 lot
Step =MarketInfo(Symb,MODE_LOTSTEP); // Step change of size

if (Lots > 0) // If lots are specified
Lts =Lots; // we work with them
else // % of free funds
Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening

if(Lts < Min_Lot) Lts=Min_Lot; // Not less than Min_Lot; // Not less than Min_Lot
if(Lts*One_Lot > Free) // Lots more expensive than Free
{
Alert(" Not enough money ", Lts," lots);
return; // Exit start()
}
//--------------------------------------------------------------- 8 --
//Open orders
if (NumberOfBarOpenLastPos()>0){
while(true) // Close order loop.
{
if (Total==0 && Opn_B==true) // No open orders
{ //open Buy criterion.
RefreshRates(); // Update data
SL=Bid - New_Stop(StopLoss)*Point; // Calculation of SL open
TP=Bid + New_Stop(TakeProfit)*Point; // Calculation of TP open.
Alert("Attempting to open Buy. Waiting for reply...");
Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP);//open Buy
if (Ticket > 0) // it worked :)
{
Alert ("Buy order opened ",Ticket;)
return; //Exit order
}
if (Fun_Error(GetLastError())==1) // Error handling
continue; // retry
return; // Exit from start()
}
if (Total==0 && Opn_S==true) // no open orders
{ //open Sell criterion.
RefreshRates(); // Update data
SL=Ask + New_Stop(StopLoss)*Point; // Calculation of SL open.
TP=Ask - New_Stop(TakeProfit)*Point; // Calculation of TP open.
Alert("Attempting to open Sell. Waiting for reply...");
Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP);//Open Sel.
if (Ticket > 0) // It worked :)
{
Alert ("Sell order opened ",Ticket;)
return; // Exit from the start()
}
if (Fun_Error(GetLastError())==1) // Error handling
continue; // retry
return; // Exit from start()
}
break; // Exit while
}
}
//--------------------------------------------------------------- 9 --
return; //exit while; //start()
}
//-------------------------------------------------------------- 10 --


//+----------------------------------------------------------------------------+
//| Author : Kim Igor V. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Version : 19.02.2008 |
//| Description : Returns the bar number of the last position opened or -1. |
//+----------------------------------------------------------------------------+
//| Parameters: |
//| sy - name of instrument ("" or NULL - current symbol) |
//| tf - timeframe ( 0 - current timeframe) |
//| op - operation ( -1 - any position) |
//| mn - MagicNumber ( -1 - any magic number) |
//+----------------------------------------------------------------------------+
intOfBarOpenLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) {
datetime t;
int i, k=OrdersTotal();

if (sy=="" || sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sy) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderOpenTime()) t=OrderOpenTime();
}
}
}
}
}
}
return(iBarShift(sy, tf, t, True))
}

int Fun_Error(int Error) // Error handling function
{
switch(Error)
{ // Errors that can be avoided.
case 4: Alert("Trade server is busy. Try again...");
Sleep(3000); // Simple solution.
return(1); // Exit function.
case 135:Alert("Price changed. Try again...");
RefreshRates(); // Refresh data.
return(1); // Exit from the function.
case 136:Alert("No price. Waiting for a new tick...");
while(RefreshRates()==false) // Till a new tick
Sleep(1); // Delay in the loop
return(1); // Exit from the function
case 137:Alert("Broker is busy. Try again...");
Sleep(3000); // Simple solution.
return(1); // Exit from the function.
case 146:Alert("The trading subsystem is busy. Try again...");
Sleep(500); // Simple decision
return(1); // Exit from the function
// Critical errors
case 2: Alert("General error;)
return(0); // Exit from the function.
case 5: Alert("Older version of the terminal.");
Work=false; // No longer work
return(0); // Exit from the function
case 64: Alert("Account blocked.");
Work=false; // No longer work
return(0); // Exit from the function
case 133:Alert("Trading prohibited.");
return(0); // Exit from the function
case 134:Alert("Not enough money to execute the transaction.");
return(0); // Exit from the function
default: Alert("An error has occurred ",Error); // Other options
return(0); // Exit from the function
}
}
//-------------------------------------------------------------- 11 --
int New_Stop(int Parametr) // Check stop-prick.
{
int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// Min. distance
if (Parametr<Min_Dist) // If less than allowed.
{
Parametr=Min_Dist; // Set tolerance.
Alert("Stop distance increased;)
}
return(Parametr); // Return value.
}
//-------------------------------------------------------------- 12 --

 
kurilko >> :

// Opening of orders

if (NumberOfBarOpenLastPos()>0)

The function returns more than 0 only if a position has been opened, if not -1 then follow...

if (NumberOfBarOpenLastPos()>0||NumberOfBarOpenLastPos()==-1)

{

}

 

Changed the condition to if (NumberOfBarOpenLastPos()>0||NumberOfBarOpenLastPos()==-1)

Still doesn't work, maybe it needs to be written somewhere else in the code?

Reason: