How to Calculate Trade Running?

%3CLINGO-SUB%20id%3D%22lingo-sub-2101285%22%20slang%3D%22en-US%22%3EHow%20to%20Calculate%20Trade%20Running%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2101285%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHello%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EI%20need%20help%20with%20filling%20the%20column%20%22Trade%20Running%22%20in%20sheet%201%20in%20the%20attached%20Excel%20File.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EWhen%20a%20Buy%20signal%20(in%20Column%20C)%20appears%2C%20then%20trade%20running%20becomes%20from%200%20to%201.%20If%20the%20stop%20loss%20price%20corresponding%20with%20the%20buy%20signal%20(column%20E)%20is%20breached%20subsequently%20before%20there%20is%20a%20sell%20signal%2C%20then%20the%20trade%20running%20becomes%20'0'.%20Otherwise%2C%20the%20trade%20running%20signal%20'1'%20continues%20until%20a%20sell%20signal%20is%20reached.%20That%20is%2C%20at%20each%20buy%20signal%20the%20trade%20running%20column%20becomes%201%20until%20the%20stop%20loss%20price%20is%20reached%20in%20column%20B%20or%20Sell%20signal%20is%20generated%20in%20column%20C.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESomeone%20provided%20me%20with%20this%20formula%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3DIF(LOOKUP(%22zzzzz%22%2C%24C%241%3AC2)%26lt%3B%26gt%3B%22Buy%22%2C0%2CIF(B2%26gt%3B%3DLOOKUP(10%5E35%2C%24E%242%3AE2)%2C1%2C0))%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIt%20works%20on%20this%20file%2C%20but%20doesn't%20work%20on%20my%20data.%20What%20is%20%22Lookup(10%5E35...%22%20implying%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIf%20anyone%20can%20find%20the%20formula%20for%20trade%20running%20in%20a%20different%20way%2C%20I%20will%20really%20appreciate%20it.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2101285%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2102636%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Calculate%20Trade%20Running%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2102636%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F931356%22%20target%3D%22_blank%22%3E%40Omer_Ad%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EActually%26nbsp%3BLOOKUP(%22zzzzz%22%2C%24C%241%3AC2)%20returns%20last%20non-empty%20value%20in%20current%20range%20(from%20C1%20to%20current%20row)%20for%20the%20column%20C%2C%20and%26nbsp%3BLOOKUP(10%5E35%2C%24E%242%3AE2)%20returns%20largest%20(more%20exactly%20largest%2C%20but%20less%20than%26nbsp%3B10%5E35%20value)%20in%20the%20current%20range%20in%20column%20E.%3C%2FP%3E%0A%3CP%3EFormula%20works%20correctly%2C%20perhaps%20you%20have%20non-blank%20cells%20in%20your%20actual%20file%20which%20only%20looks%20like%20blank%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2103267%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Calculate%20Trade%20Running%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2103267%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20response.%20I%20really%20appreciate%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%202423%20rows%20in%20my%20data.%20Column%20C%20in%20this%20file%20is%20column%20P%20in%20my%20file.%20Column%20B%20in%20this%20file%20is%20column%20B%20in%20my%20file.%20And%2C%20column%20E%20in%20this%20file%20is%20column%20AJ%20in%20my%20file.%20So%2C%20when%20I%20change%20the%20formula%20for%20columns%2C%20it%20should%20look%20like%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIF(LOOKUP(%22zzzzz%22%2C%24P%241%3AP2)%26lt%3B%26gt%3B%22Buy%22%2C0%2CIF(B2%26gt%3B%3DLOOKUP(10%5E35%2C%24AJ%242%3AAJ2)%2C1%2C0))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20checked%20and%20deleted%20everything%20in%20my%20target%20column.%20However%2C%20what%20happens%20is%20that%2C%20I%20get%20all%200s%20except%201s%20where%20there%20is%20a%20buy%20signal.%20In%20other%20words%2C%20the%201s%20ought%20to%20continue%20until%20the%20stop%20loss%20is%20reached%20or%20the%20sell%20signal%20is%20reached%20(whichever%20comes%20first)%2C%20but%201s%20only%20appear%20next%20to%20the%20buy%20signals%20in%20my%20file...am%20I%20making%20a%20mistake%20when%20switching%20the%20formula%20from%20this%20file%20to%20my%20file%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello,

I need help with filling the column "Trade Running" in sheet 1 in the attached Excel File.

When a Buy signal (in Column C) appears, then trade running becomes from 0 to 1. If the stop loss price corresponding with the buy signal (column E) is breached subsequently before there is a sell signal, then the trade running becomes '0'. Otherwise, the trade running signal '1' continues until a sell signal is reached. That is, at each buy signal the trade running column becomes 1 until the stop loss price is reached in column B or Sell signal is generated in column C.

 

Someone provided me with this formula:

 

=IF(LOOKUP("zzzzz",$C$1:C2)<>"Buy",0,IF(B2>=LOOKUP(10^35,$E$2:E2),1,0))

 

It works on this file, but doesn't work on my data. What is "Lookup(10^35..." implying?

 

If anyone can find the formula for trade running in a different way, I will really appreciate it.

6 Replies

@Omer_Ad 

Actually LOOKUP("zzzzz",$C$1:C2) returns last non-empty value in current range (from C1 to current row) for the column C, and LOOKUP(10^35,$E$2:E2) returns largest (more exactly largest, but less than 10^35 value) in the current range in column E.

Formula works correctly, perhaps you have non-blank cells in your actual file which only looks like blank?

@Sergei Baklan 

 

Thanks for your response. I really appreciate this.

 

I have 2423 rows in my data. Column C in this file is column P in my file. Column B in this file is column B in my file. And, column E in this file is column AJ in my file. So, when I change the formula for columns, it should look like:

 

=IF(LOOKUP("zzzzz",$P$1:P2)<>"Buy",0,IF(B2>=LOOKUP(10^35,$AJ$2:AJ2),1,0))

 

I checked and deleted everything in my target column. However, what happens is that, I get all 0s except 1s where there is a buy signal. In other words, the 1s ought to continue until the stop loss is reached or the sell signal is reached (whichever comes first), but 1s only appear next to the buy signals in my file...am I making a mistake when switching the formula from this file to my file?

@Sergei Baklan 

 

For instance, when I add the formula in the file I have attached in this post, I don't get the results that I am getting in the file I attached in my first post.

@Omer_Ad 

That since the cells in column C which are empty are not blank, they have some not-printable character. You may select all such empty cells and clean them by Del, or modify the formula as

=IF(LOOKUP(2,1/(LEN($C$1:C2)>0),$C$1:C2)<>"Buy",0,IF(B2>=LOOKUP(10^35,$E$2:E2),1,0))

Most probably you copy/paste data from web or like.

@Sergei Baklan 

 

Thank You for your response.

 

However, this formula doesn't work because if the price goes below the stop loss price, column F becomes 0 and, after that, becomes 1 once again (when it should become 1 at the next buy signal). For instance, in the attached file, in row 289 there is a buy signal with a corresponding stop loss price of 5.0847...in row 295 the price goes below the stop loss price, and the trade is terminated. However, row 296 becomes 1 again in column F. This should become 1 in row 376 when there is a buy signal.

 

I will highly appreciate it if you can provide me a formula to help me navigate this problem.

@Omer_Ad 

I added couple of named cells

image.png

Please note they are with RELATIVE references. With that formula could be

=IF(LOOKUP(2,1/(LEN($C$1:C2)>0),$C$1:C2)<>"Buy",0,IF(B2>=LOOKUP(10^35,$E$2:E2),IF((LEN(CellLeft)=0)*(CellUp=0),0,1),0))