[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 176

 

Can you tell me how to correctly compare the current price or the moving average with the trend line?

Thank you in advance.

    double maH_fast=iMA(NULL,fast_maH_timeframe,fast_maH_period,0,fast_maH_method,fast_maH_price,0);

    if (ObjectFind("Tr_S1")==-1)
     {
      Create_Tr_S("Tr_S1",White,timf2s,TF2S,timf1s,TF1S);
     }

    if(maH_fast>"Tr_S1")
     {...}
 
ikatsko:

HOW WOULD YOU COUNT THE NUMBER OF PROFITABLE LONG POSITIONS AND THE NUMBER OF PROFITABLE SHORT POSITIONS SEPARATELY?

The strategy is as follows: if the number of profitable long positions since the start of the EA (or better - for the entire account history) is greater than the number of short positions, then only long positions should be allowed to be opened. And vice versa.

It is clear how to count these deals, if they are closed by the Expert Advisor: Close - Count. But if a position is closed by TP or SL, then ... ?

Maybe someone has a ready code of the function?


int ProfitableOrdersOfLongs(){
   int i,Orders=0; 
   for(i=0;i<OrdersHistoryTotal();i++){
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
      if(OrderSymbol()!=Symbol())continue;
      if(OrderMagicNumber()!=Magic)continue;
      if(OrderType()==0)if(OrderProfit()>0) Orders++;              
    }  
return(Orders);} 
//====================================================================================================== 
int ProfitableOrdersOfShorts(){
   int i,Orders=0; 
   for(i=0;i<OrdersHistoryTotal();i++){
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
      if(OrderSymbol()!=Symbol())continue;
      if(OrderMagicNumber()!=Magic)continue;
      if(OrderType()=1)if(OrderProfit()>0) Orders++;              
    }  
return(Orders);} 
 
nemo811:

Can you tell me how to correctly compare the current price or the moving average with the trend line?

Thank you in advance.

A trend line has a start point with time-price coordinates and an end point with time-price coordinates.

You can use the straight line equation with the same coordinates to find the price level at any point that is between these two coordinates of the constructed segment and compare the price levels of MAA and the crossing point of the desired bar with this line...

You can read - there is a detailed description of such an example.

 
Roman.:

You take the last closed order, compare its close time with the previous closed one using OrderCloseTime(), if it is the same, you compare it with the close time of your previous closed order... like this, naturally, it's all in a loop - from the last closed to the first, you go one after another and compare the time of orders closure... Another thing - print the closing time of the last orders you know beforehand, let's say three orders , it may be different, even if you understand it as " simultaneously", i.e. as I understand it, the order closes at any time, i.e. Actually, the time of closing of, say, three orders at once cannot be the same - try to print() and see the values of your three TIME orders - their values of OrderCloseTime() characteristics, i.e., we may have to introduce the concept of TIME of closing, i.e., deviation of closing time of several orders by some small value when we may consider that they have closed simultaneously. Experiment and see for yourselves from here.

Thank you it worked, but now it opens a multiple order

I did it like this

OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);//выбрать последний ордер 
tik=OrderCloseTime();
for (int l=OrdersHistoryTotal(); l>=0; l--) 
{
OrderSelect(l, SELECT_BY_POS, MODE_HISTORY);
if (OrderType()==OP_BUY||OP_SELL)
 {
  if (OrderMagicNumber()==1)
   {
   if (OrderProfit()<0)
    {
     if (OrderClosePrice()!= OrderStopLoss())
     {
     if (tik<=OrderCloseTime())
     {
 
vik-777:

Thank you it worked, but now a multiple order opens

I did it like this

Problem solved. Thank you all.

OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);//выбрать последний ордер 
tik=OrderCloseTime();
for (int l=OrdersHistoryTotal(); l>=0; l--) 
{
OrderSelect(l, SELECT_BY_POS, MODE_HISTORY);
if (OrderType()==OP_BUY||OP_SELL)
 {
  if (OrderMagicNumber()==1)
   {
   if (OrderProfit()<0)
    {
     if (OrderClosePrice()!= OrderStopLoss())
     {
     if (tik<=OrderCloseTime())
     {
     a = OrdersHistoryTotal();
     if (a>w)
     {
     if (sarik>0)
      {   
      OrderSend(Symbol(),OP_BUY,Lot1,NormalizeDouble(Ask,4),1,Ask - SL1*Point,Ask + 10*Point,0,2);
      w++;
      }
 
nemo811:

Can you tell me how to correctly compare the current price or moving average with the trend line?

1. if(maH_fast>"Tr_S1") {...} -- error: maH_fast is a real number, "Tr_S1"- value of the string type;
2. double ObjectGetValueByShift( string name, int shift)
The function calculates and returns the price value for the specified bar (offset from the current bar). The price value is calculated using the linear equation based on the first and second coordinates. Applies to trendlines.
Parameters:
name - Object name.
shift - Number of bar.
Example: double price=ObjectGetValueByShift("MyTrendLine#123", 11);
 
Hello! I have this question... let's say iHighest and iLowest can be used to find out the bar number with the maximum value of high/low for a certain period, but how can I find out the maximum value of the st Dev indicator for a certain number of bars?
 
double maxdev,mindev=1;
for(int i=0;i<counbar;i>0)
{
double val=iStdDev(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,i);
if(mindev>val)mindev=val;
if(maxdev<val)maxdev=val;
}
Print("maxdev - ",maxdev," mindev - ",mindev);
Somewhere like this.
 
7sintez:

I've looked at everything, I've done everything... It won't open a position, that's all! It closes properly, but it doesn't open... I don't know what to do! Maybe someone will find a bug in the program?




It opens and closes orders on 5 min EURUSD correctly. Slight modification problems, often tries to modify with the same values, therefore frequent errors.
 

Hi all. Help for a beginner, please:

Bottom line.

1)period is 1 day.

2)There is an OrderSend(...) open order. It has SL and TP. But as an additional condition to the stop and loss, we have to set the order to live from the moment it was opened up to 18 hours, and then close it at the current price.

This means that one of three conditions must be met:

1. a stop loss is triggered

or

2. take profit is triggered

or

3. Since neither Stop Loss nor Take Profit has been triggered, the position is closed 18 hours after it was opened at the then current price.

Here's how to set this time condition, eh???


Question 2:

How to correctly spell out the condition that the event should occur if( 1 day period):

- CLOSE of the current bar is greater than C of the preceding bar and greater than C of the preceding bar, and C of the preceding bar is also greater than C of the preceding bar.


Please, don't be angry. I was sitting on Rumus before, and I'm in the process of rebuilding...

Reason: