suprsnipes Posted June 1, 2009 Share Posted June 1, 2009 Need help with PHP translation from Excel to PHP. I can classify almost 80% of the data using queries but where I am running into problems is as you can tell from the formula I am comparing the current row with the previous row of data and the previous rows needs to be updated correctly before moving to the next. Here is the statement in Excel: =IF(AND(E2="trd",F3<>"",H2<=F3),"Sell",IF(AND(E2="trd",I3="Buy",H2<H3),"Sell ",IF(AND(E2="trd",I3="Sell",H2<=H3),"Sell",IF(AND(E2="trd",I3="Sell",H2>H3), "Buy",IF(AND(E2="trd",H2>=G3),"Buy",IF(AND(E2="trd",I3="Buy",H2>=H3),"Buy",I F(AND(E2="trd",H2>3000,F3>3000,H2>F3),"Buy","")))))))&IF(AND(E2="trd",G3<>"" ,H2<G3),"Sell","") E2 = Trade F3 = Previous BP H2 = TP H3 = Previous TP I3 = Previous Class G3 = Previous AP Translating into business logic: IF(AND(TRADE="trd",PREVIOUS_BP<>"",TP<=PREVIOUS_BP),"Sell", IF(AND(TRADE="trd",PREVIOUS_CLASS="Buy",TP<PREVIOUS_TP),"Sell", IF(AND(TRADE="trd",PREVIOUS_CLASS="Sell",TP<=PREVIOUS_TP),"Sell", IF(AND(TRADE="trd",PREVIOUS_CLASS="Sell",TP>PREVIOUS_TP),"Buy", IF(AND(TRADE="trd",TP>=PREVIOUS_AP),"Buy", IF(AND(TRADE="trd",PREVIOUS_CLASS="Buy",TP>=PREVIOUS_TP),"Buy", IF(AND(TRADE="trd",TP>3000,PREVIOUS_BP>3000,TP>PREVIOUS_BP),"Buy","") ) ) ) ) ) ) &IF(AND(TRADE="trd",PREVIOUS_AP<>"",TP<PREVIOUS_AP),"Sell","") If any member is willing to help me out here I would be very appreciative. Link to comment https://forums.phpfreaks.com/topic/160455-php-freaks-need-help-with-php-translation/ Share on other sites More sharing options...
anupamsaha Posted June 1, 2009 Share Posted June 1, 2009 Will the following work for you? <?php switch($trade) { case 'trd': if ($previous_bp <> '' and $tp <= $previous_bp) { echo 'Sell'; } else if (($previous_class == 'Buy' or $previous_class == 'Sell') and $tp <= $previous_tp) { echo 'Sell'; } else if ($previous_class == 'Sell' and ($tp > $previous_tp or $tp >= $previous_ap)) { echo 'Buy'; } else if ($previous_class == 'Buy' and $tp >= $previous_tp) { echo 'Buy'; } else if ($tp > 3000 and $previous_bp > 3000 and $tp > $previous_bp) { echo 'Buy'; } else { echo ''; } break; default: // Do stuff here where $trade != 'trd' } ?> Link to comment https://forums.phpfreaks.com/topic/160455-php-freaks-need-help-with-php-translation/#findComment-846748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.