What If filter by month

4 replies

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

9 years ago #112399

I’m posting a sample code that adds new What If condition that allows you to filter by month.

 

Just open QuantEditor, create w new What If file and copy the contents there:

 

import java.util.ArrayList;
import java.util.Iterator;
 
import com.sonarbytes.eaa.logic.whatif.WhatIf;
import com.sonarbytes.strategy.Order;
import com.sonarbytes.strategy.StrategyStatsData;
import com.sonarbytes.windows.panels.propertyPanel.CComboBoxItemList;
import com.sonarbytes.utils.SQTime;
 
public class ByMonth extends WhatIf {
 
public ByMonth() {
setName("By month");
 
      addIntParameter("_JAN_", "January", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_FEB_", "February", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_MAR_", "March", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_APR_", "April", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_MAY_", "May", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_JUN_", "Jun", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_JUL_", "July", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_AUG_", "August", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_SEP_", "September", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_OCT_", "October", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_NOV_", "November", 1, 1, Integer.MAX_VALUE, 1);
      addIntParameter("_DEC_", "December", 1, 1, Integer.MAX_VALUE, 1);
        
        // set name of this method that will be displayed with parameter(s)
setFormatedName("By month");
}
 
/**
* Function receives list of all orders sorted by open time and it could manipulate 
* the list and remove any order that matches certain filter from the list.     
* 
* 
* Order structure:
*   .ticket - order ticket (integer number)
*   .size - order size
*   .type - order type: 1 - long trade, 2 - short trade     
*   .pl - trade resulting Profit/Loss in $
*   .pctPL - trade resulting Profit/Loss in %
*   .pipsPL - trade resulting Profit/Loss in pips
*   .openPrice - opening price of an order
*   .openTime - opening time of an order (in seconds from 1.1.1970)
*   .stoploss - stop loss level set on the trade
*   .takeprofit - profit target level set on the trade
*   .closePrice - closing price of an order
*   .closeTime - closing time of an order (in seconds from 1.1.1970)
*   .closeType - closing type
*   .DD - drawdown during this trade in $                                            
*   .pctDD - drawdown during this trade in %                                            
*   .pipsDD - drawdown during this trade in pips
*   .accountBalance - account balance during this trade                                                 
*   .symbol - instrument symbol (for example "EURUSD")
*                    
* @param originalOrders - list of original orders that can be changed. Each order has the order properties specified above
*/    
@Override
public void filter(ArrayList<Order> originalOrders) {
int jan = getIntParameterValue("_JAN_");
      int feb = getIntParameterValue("_FEB_");
      int mar = getIntParameterValue("_MAR_");
      int apr = getIntParameterValue("_APR_");
      int may = getIntParameterValue("_MAY_");
      int jun = getIntParameterValue("_JUN_");
      int jul = getIntParameterValue("_JUL_");
      int aug = getIntParameterValue("_AUG_");
      int sep = getIntParameterValue("_SEP_");
      int oct = getIntParameterValue("_OCT_");
      int nov = getIntParameterValue("_NOV_");
      int dec = getIntParameterValue("_DEC_");
 
for(Iterator<Order> i = originalOrders.listIterator(); i.hasNext() ;) {
Order order = (Order)i.next();  
         SQTime time = new SQTime(order.openTime);
         int orderMonth = time.getMonth();
  
if(orderMonth == 0 && jan != 1) i.remove();
         if(orderMonth == 1 && feb != 1) i.remove();
         if(orderMonth == 2 && mar != 1) i.remove();
         if(orderMonth == 3 && apr != 1) i.remove();
         if(orderMonth == 4 && may != 1) i.remove();
         if(orderMonth == 5 && jun != 1) i.remove();
         if(orderMonth == 6 && jul != 1) i.remove();
         if(orderMonth == 7 && aug != 1) i.remove();
         if(orderMonth == 8 && sep != 1) i.remove();
         if(orderMonth == 9 && oct != 1) i.remove();
         if(orderMonth == 10 && nov != 1) i.remove();
         if(orderMonth == 11 && dec != 1) i.remove();
} 
}
}

Mark
StrategyQuant architect

0

ynachum

Customer, bbp_participant, community, 21 replies.

Visit profile

9 years ago #126924

Do you have perhaps any other what-if codes already written like this one?…

Yossi

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

9 years ago #126949

You can see the code of all the What-if options already used in the program, just open the QuantEditor in EA Analyzer.

Mark
StrategyQuant architect

0

ForexTrader

Subscriber, bbp_participant, community, 34 replies.

Visit profile

9 years ago #127435

I got this error Mark:

 

class ByMonth is public, should be declared in a file named ByMonth.java

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

9 years ago #127441

yes, I don’tknow where you created it, but you should create a file named ByMonth.java in QuantEditor and put this code there.

 

File name must be as same as class name.

Mark
StrategyQuant architect

0

Viewing 4 replies - 1 through 4 (of 4 total)