Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 392

 
Link_x:

The robot will then make only two trades (buy/sell) because the signal is derived from the position of the two lines (Line_1 > Line_2 or Line_2 > Line_1).
It should be like this:

1) If Line_1 is higher than Line_2, a buy trade is made..,
2) The deal is closed at SL or TP,
3) If Line_1 is above Line_2, a trade is not executed until conditions change. .
4) If Line_2 is higher than Line_1, a buy trade is executed,
5) The trade is closed at SL or TP,
6) If Line_2 is above Line_1, a trade is not executed until conditions change. .

Code 1,2,4,5 parts - I can create, but 3 and 6 I cannot.


And operations have been abandoned over time, there is still a large amount of work. with 3 and 6 is not difficult to help
 
Link_x:

Then the robot will make only two trades (buy/sell) because the signal comes from the position of two lines (Line_1 > Line_2 or Line_2 > Line_1).
It should be like this:

1) If Line_1 is higher than Line_2, a buy trade is made..,
2) The deal is closed at SL or TP,
3) If Line_1 is above Line_2, a trade is not executed until conditions change. .
4) If Line_2 is higher than Line_1, a buy trade is executed,
5) The trade is closed at SL or TP,
6) If Line_2 is above Line_1, a trade is not executed until conditions change. .

Code 1,2,4,5 parts - I can create, but 3 and 6 I cannot.

On the third point. It's a familiar situation, but I don't know the solution. I have the same problem. What is needed here is fixing the stop so that it sets a flag. Signal + stop = false flag.

But, how do you get information from triggering a stop that it's triggered?

 
Forexman77:

On the third point. It's a familiar situation, but I don't know the solution. I have the same problem. What is needed here is fixing the stop so that it sets a flag. Signal + stop = false flag.

But how do I get information from triggering of a stop, that it has triggered?


It is always possible to get a signal to close an order, if you want to
 
Vinin:

It is always possible to get a signal to close an order, if you want to.
When it is not at stop or take profit, it is not a problem. I will have to check if there is a function that gives information on stops and take profit.
 
Vinin:

And operations have been abandoned over time, there's still a lot of work to be done. with 3 and 6 it's not hard to help

I will still work on these operations.

I have a different goal today.

Today I need to overcome "not making transactions at the source".

 
Forexman77:
When it closes on something other than a stop or a take, it is not a problem. I will have to check if there is a function that gives information on stops and take profit.
There is no such function. But we can compare close and stop prices. Although, it is not reliable due to slippage. But we can do it comparing to the delta - there will be a probability of getting what is closed by the stop order. You can read the comment of a closed order - they contain information about the method of closing.
 
There is an option.
When there is a buy trade, a special Buy_Key string is created.
When there is a Sell transaction, a special Sell_Key string is created.
If Buy_Key is followed by Buy_Key then no Buy deal is made.
If Sell_Key is followed by Sell_Key, no Sell deal is executed.
If Buy_Key is followed by Sell_Key then Sell transaction is executed.
If Sell_Key is followed by Buy_Key then a Buy trade is executed.

The question arises: "Where and how to write?
 
Link_x:
There is an option.
When there is a buy trade, a special Buy_Key string is created.
When there is a Sell transaction, a special Sell_Key string is created.
If Buy_Key is followed by Buy_Key then no Buy deal is made.
If Sell_Key is followed by Sell_Key, no Sell deal is executed.
If Buy_Key is followed by Sell_Key then Sell transaction is executed.
If Sell_Key is followed by Buy_Key then a Buy trade is executed.

The question arises: "Where and how to write?
Into a notebook like "notepad". :)
 
TarasBY:
Into a notebook-type notebook. :)

I laughed. :)

Just kidding, would a comment when opening an order be able to perform this function?
If we represent Buy_Key as -1, and Sell_Key as 1, we can arrange a skip function X when an order is opened, through the fulfillment of an if condition.
The logical chain of the skip function X:
Buy_Key = -1
Sell_Key = 1
0 Open some trade.
1 Identify order type by comment.
1.1 If the Buy_Key comment is a Buy.
1.2 If the comment is Sell_Key, sell.
2 Opening of a subsequent trade.
1.1 If X is greater than zero, it is possible to open a Buy trade and impossible to open a Sell trade.
1.2 If X is less than zero, a Sell trade may be opened, and a Buy trade cannot be opened.
3 Repeat the cycle.

Again the question is: "How to make X variable dependent on Sell_Key or Buy_Key?
 
Link_x:

That's a laugh. :)

Just kidding, will the comment when opening an order be able to perform this function?
If we represent Buy_Key as -1, and Sell_Key as 1, we can arrange a skipping function X when an order is opened, through the fulfillment of an if condition.
The logical chain of the skip function X:
Buy_Key = -1
Sell_Key = 1
0 Opening of a trade.
1 Determine the order type based on the comment.
1.1 If the Buy_Key comment is a Buy.
1.2 If the comment is Sell_Key, sell.
2 Opening of a subsequent trade.
1.1 If X is greater than zero, it is possible to open a Buy trade and impossible to open a Sell trade.
1.2 If X is less than zero, a Sell trade may be opened, and a Buy trade cannot be opened.
3 Repeat the cycle.

Again the question is: "How do I make the X variable dependent on Sell_Key or Buy_Key?"

You're looking in the wrong direction. Are you making for the tester or for the real thing? There's a significant difference.

If for real, forget about flags that can be lost in abnormal situations. Better to look for everything in the trading environment.