Help with code with ATR new entry

Hello
I am trying to make a system code, but it´s not correct.

 indicator1= RSI(10);
 indicator2= RSI(6);
 
 buycondition= indicator1 < 30 ;
 sellcondition= indicator2 > 70;
 InTrade = Flip( Buy, Sell ); 
 newentrycondition = Close < ValueWhen(Buy, Close)-(2*ATR(10));
 
 Buy = buycondition OR
  IIf (InTrade AND newentrycondition, sigScaleIn, 0);
 Sell= sellcondition;

My idea is :
First purchase = indicator1 <30
if the price goes up sell when indicator2> 70
if the price falls below the price of the first entry-2*ATR(10) it would be bought again.
If price continues to go down, buy again when the price is less than -2 * ATR of the previous purchase.

and so on continuously until the exit condition where all positions are closed is met.

I attach the code (erroneous) that I have tried to do, in case someone can help me with it.
Thank you.